Skip to content Skip to sidebar Skip to footer

Update Json Nodes In Python Using Jsonpath

I'm trying to modify json data based on a jsonpath expression: { 'SchemeId': 10, 'nominations': [ { 'nominationId': 1 } ] } Using something

Solution 1:

I figured this out so I can share here. The update() method changes the values.

from jsonpath_ng import jsonpath, parse
import json
data = json.loads('''{"SchemeId": 10, "nominations": [ { "nominationId": 1 } ] }''')
jsonpath_expr = parse('$.SchemeId')
jsonpath_expr.find(data)
jsonpath_expr.update(data, 11)
print(json.dumps(data, indent=2))

Post a Comment for "Update Json Nodes In Python Using Jsonpath"