Answers for "create json python"

8

print json python

import json

uglyjson = '{"firstnam":"James","surname":"Bond","mobile":["007-700-007","001-007-007-0007"]}'

#json.load method converts JSON string to Python Object
parsed = json.loads(uglyjson)

print(json.dumps(parsed, indent=2, sort_keys=True))
Posted by: Guest on May-14-2020
4

how to create json file in python

#import the json module
import json 

#create a dictionary which we can add to a json file
dictionary ={ 
    "name" : "sathiyajith", 
    "rollno" : 56, 
    "cgpa" : 8.6, 
    "phonenumber" : "9976770500"
} 

#open an object with following inputs: 'name_of_file.json', 'w'
#dump the content fromt he dictionary into the outfile
with open("sample.json", "w") as outfile: 
    json.dump(dictionary, outfile)
Posted by: Guest on November-20-2020
1

generate json in python

# JSON objects and JSON string objects can be created by reading a file directly 
# with the json.load() and json.dump() functions.

data_set = {"key1": [1, 2, 3], "key2": [4, 5, 6]}

json_dump = json.dumps(data_set)

print(json_dump)

# String of JSON object

OUTPUT
{"key1": [1, 2, 3], "key2": [4, 5, 6]}

json_object = json.loads(json_dump)

print(json_object["key1"])

# JSON object

OUTPUT
[1, 2, 3]
Posted by: Guest on July-05-2021
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
0

json.loads

>>> 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']
Posted by: Guest on September-15-2020

Python Answers by Framework

Browse Popular Code Answers by Language