Skip to content Skip to sidebar Skip to footer

Python - Change Json Values And Pretty Print

How to change Values in JSON by using Python in any of the nodes (value1, value2, value3, value4, value5, value6, value7): { 'key1': 'value1', 'level2': { 'key2': '

Solution 1:

You'll want to first convert the string to a python dictionary, then manipulate the dictionary, and finally dump the dictionary back to a string. Here's a simple example:

import json
json_string = '{"foo": "bar"}'
json_dict = json.loads(json_string)
json_dict["foo"] = "baz"
print json.dumps(json_dict, indent=4)

Post a Comment for "Python - Change Json Values And Pretty Print"