Answers for "python object to json file"

63

python read json file

import json

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

print(data)
Posted by: Guest on April-08-2020
6

python json dump to file

import json
with open('data.json', 'w') as f:
    json.dump(data, f)
Posted by: Guest on August-15-2020
1

python object to json file

data = {
  "your json": "has data!"
}

with open('data.txt', 'w') as outfile:
    json.dump(data, outfile)
Posted by: Guest on October-06-2021
2

Convert from JSON to Python

import json

# some JSON:
x =  '{ "name":"John", "age":30, "city":"New York"}'

# parse x:
y = json.loads(x)

# the result is a Python dictionary:
print(y["age"])
Posted by: Guest on February-01-2021

Code answers related to "python object to json file"

Python Answers by Framework

Browse Popular Code Answers by Language