Load json file

Code examples

53
0

python read json file

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)

print(data)
12
0

open json file python

import json

with open('data.txt') as json_file:
    data = json.load(json_file)
7
0

write json pythonb

import json

data = {}
data['people'] = []
data['people'].append({
    'name': 'Scott',
    'website': 'stackabuse.com',
    'from': 'Nebraska'
})
data['people'].append({
    'name': 'Larry',
    'website': 'google.com',
    'from': 'Michigan'
})
data['people'].append({
    'name': 'Tim',
    'website': 'apple.com',
    'from': 'Alabama'
})

with open('data.txt', 'w') as outfile:
    json.dump(data, outfile)
3
0

read json file python

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)
print(data)

flx = json.dumps(data, ensure_ascii=False, indent=4)
print(flx)
2
0

save json to file

import json

data = {}

with open('data.txt', 'w') as outfile:
    json.dump(data, outfile)
0
0

python json load file

import json

# with json load  (file)
info = open('data.json',)
res = json.load(info)
print(res)
print("Datatype after deserialization : " + str(type(res)))
#>>> {'name': 'Dave', 'City': 'NY'}
#>>> Datatype of the serialized JSON data : <class 'dict'>

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................