Add element to a json in python -
i trying add element json file in python not able it.
this tried untill (with variation deleted):
import json data = [ { 'a':'a', 'b':(2, 4), 'c':3.0 } ] print 'data:', repr(data) var = 2.4 data.append({'f':var}) print 'json', json.dumps(data)
but, is:
data: [{'a': 'a', 'c': 3.0, 'b': (2, 4)}] json [{"a": "a", "c": 3.0, "b": [2, 4]}, {"f": 2.4}]
which fine because need add new row instead element want this:
[{'a': 'a', 'c': 3.0, 'b': (2, 4), "f":2.4}]
how should add new element?
you can this.
data[0]['f'] = var
Comments
Post a Comment