Answers for "json data in python"

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
2

Json in python

import json

json_file = json.load(open("your file.json", "r", encoding="utf-8"))

# For see if you don't have error:
print(json_file)
Posted by: Guest on October-16-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