Answers for "generate json in python"

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

Python Answers by Framework

Browse Popular Code Answers by Language