python - JSON values to String values -


need convert below json strictly string quoted valued json using python. there python "json" module method can make use of, or there simpler parsing code can use achieve this.

from :

data = '[{"id":334,"type":"c","raw":{"field_val":11}}]' =>      [           {             "id":334,             "type":"c",             "raw":{                     "field_val":11                   }             }         ] 

to:

'[{"id":"334","type":"c","raw":{"field_val":"11"}}]' 

the json module want.

import json  string = '''[           {             "id":334,             "type":"c",             "raw":{                     "field_val":11                   }             }         ]'''  mylist = json.loads(string) print(mylist) 

the output is:

[{u'raw': {u'field_val': 11}, u'type': u'c', u'id': 334}] 

then can use json.dumps():

print(json.dumps(mylist,)) 

output:

'[{"raw": {"field_val": 11}, "type": "c", "id": 334}]' 

and if want indentation:

print(json.dumps(mylist, indent=4)) 

output:

[     {         "raw": {             "field_val": 11         },          "type": "c",          "id": 334     } ] 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -