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"])
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)
#load and print elements of a json file
import json
file = "my_json_file.json"
Json = json.load(open(file)) #Json is a dictionary
print(Json)
#OUTPUT: '{ "name":"John", "age":30, "city":"New York"}'
print("Hello",Json["name"])
#OUTPUT: Hello John
# Python program showing
# use of json package
import json
# {key:value mapping}
a ={"name":"John",
"age":31,
"Salary":25000}
# conversion to JSON done by dumps() function
b = json.dumps(a)
# printing the output
print(b)
{
"Icons":{
"app icon": "your icon.ico",
"eg icon": "eg.ico"
}
}
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"])
import json
# some JSON:
p = '{"name":"John Smith"}'
person = json.loads(p)
print(y["name"])
>>> import json
>>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
>>> print(json.dumps(""fooar"))
""fooar"
>>> print(json.dumps('u1234'))
"u1234"
>>> print(json.dumps(''))
""
>>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
{"a": 0, "b": 0, "c": 0}
>>> from io import StringIO
>>> io = StringIO()
>>> json.dump(['streaming API'], io)
>>> io.getvalue()
'["streaming API"]'