Python example: to and from JSON string
Last modified: March 18, 2021
xxxxxxxxxx
example = {
"intField": 1,
"strField": "hello",
"boolField": False
}
print("default python representation")
print(example)
import json
# to json
example_json = json.dumps(example, indent=2)
print("json:")
print(example_json)
# load json
parsed_obj = json.loads(example_json)
assert parsed_obj['intField'] == example['intField']
example_json
Result
Console output