Traverse and Accessing inner elements in JSON
For me it looks that you have a nested JSON string here. And inner JSON isn't valid. So we have to fix it before parsing.
import json
with open("new1.json") as json_file:
data = json.load(json_file)
innerstr = data["j1"][0]["Data"]
innerstr = innerstr.replace("values",'"walues"').replace("time",'"time"').replace("val",'"val"').replace("walues","values")
inner = json.loads(innerstr)
#then we can modify inner data as we want
inner["dump"][0]["values"][0]["name"] = "ABC"
inner["dump"][0]["values"][1]["name"] = "CBA"
And now we has inner
variable like this
{'dump': [{'values': [{'name': 'ABC', 'time': 1586826385724, 'val': 5.12},
{'name': 'CBA', 'time': 1587576460460, 'val': 3.312}]}]}
It is a Relaxed JSON format. There is a A relaxed JSON parser for Python. Here is the example:
>>> import relaxedjson
>>> relaxedjson.parse('{moose: "goose"}')
{'moose': 'goose'}