Python Examples: to and from JSON string

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