How to modify nested JSON with python -


i need update (crud) nested json file using python. able call python function(s)(to update/delete/create) entires , write json file.

here sample file.

i looking @ the remap library not sure if work.

    {   "groups": [     {       "name": "group1",       "properties": [         {           "name": "test-key-string",           "value": {             "type": "string",             "encoding": "utf-8",             "data": "value1"           }         },         {           "name": "test-key-integer",           "value": {             "type": "integer",             "data": 1000           }         }       ],       "groups": [         {           "name": "group-child",           "properties": [             {               "name": "test-key-string",               "value": {                 "type": "string",                 "encoding": "utf-8",                 "data": "value1"               }             },             {               "name": "test-key-integer",               "value": {                 "type": "integer",                 "data": 1000               }             }           ]         }       ]     },     {       "name": "group2",       "properties": [         {           "name": "test-key2-string",           "value": {             "type": "string",             "encoding": "utf-8",             "data": "value2"           }         }       ]     }   ] } 

i feel i'm missing in question. in event, understand want read json file, edit data python object, write out updated data?

read json file:

import json  f = open("data.json") raw_data = f.read() f.close()  data = json.loads(raw_data) 

that creates dictionary (given format you've given) can manipulate want. assuming want write out:

json_data = json.dumps(data)  f = open("data.json","w") f.write(json_data) f.close() 

Comments