Answers for "python load json string"

14

python read json

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)
Posted by: Guest on March-24-2021
13

python json string to object

import json

x =  '{ "name":"John", "age":30, "city":"New York"}'
y = json.loads(x)

print(y["age"])
Posted by: Guest on May-14-2020
3

python to json

# a Python object (dict):
x = {
  "name": "John",
  "age": 30,
  "city": "New York"
}

# convert into JSON:
y = json.dumps(x)
Posted by: Guest on May-02-2020
0

get json data python

import json

# Load json data
with open("example.json", "r") as file:
  json.load(file)
  
# Save dict to json
with open("example2.json", "w") as file:
  data = {"numbers": [1,2,3]}
  json.dump(data, file, indent=2)
Posted by: Guest on July-25-2021

Python Answers by Framework

Browse Popular Code Answers by Language