RORI
0
Q:

json.loads

# Python program to read 
# json file 
   
   
import json 
   
# Opening JSON file 
f = open('data.json',) 
   
# returns JSON object as  
# a dictionary 
data = json.load(f) 
   
# Iterating through the json 
# list 
for i in data['emp_details']: 
    print(i) 
   
# Closing file 
f.close() 
2
>>> import json
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
['foo', {'bar': ['baz', None, 1.0, 2]}]
>>> json.loads('"\\"foo\\bar"')
'"foo\x08ar'
>>> from io import StringIO
>>> io = StringIO('["streaming API"]')
>>> json.load(io)
['streaming API']
2
# a Python object (dict):
x = {
  "name": "John",
  "age": 30,
  "city": "New York"
}

# convert into JSON:
y = json.dumps(x)
2
>>> import json
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
['foo', {'bar': ['baz', None, 1.0, 2]}]
>>> json.loads('"\\"foo\\bar"')
'"foo\x08ar'
>>> from io import StringIO
>>> io = StringIO('["streaming API"]')
>>> json.load(io)
['streaming API']
1

    json.dumps(x, indent=4)
 
-1

New to Communities?

Join the community