I have a Json object and Im trying to add a new element every time I enter a new number. The Json looks like this:
[
{
"range": [1,2,3,4,5]
}
]
This is my code:
import json
number = raw_input("enter a number: ")
json_file = 'json.json'
json_data = open(json_file)
data = json.load(json_data)
data.append({"range": number})
print data
If my new number is 10 for example, I want my new json document to have: [1, 2, 3, 4, 5, 10]. The output I'm getting with my code is:
[{u'range': [1, 2, 3, 4, 5]}, {'range': '25'}]
I'm using python 2.6