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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -