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
Post a Comment