Answer the question
In order to leave comments, you need to log in
How to add a string / ki to a json file in python?
Welcome all.
The point is this.
{"values": [
{"date": {"year": 2015,"month": 5,"day": 23},"pay": 4578,"cons": 2000},
{"date":{"year":2018,"month":8,"day":20},"pay":810079,"cons":174349},
{"date":{"year":2018,"month":8,"day":19},"pay":1405087,"cons":228148},
{"date":{"year":2018,"month":8,"day":18},"pay":310057,"cons":129969},
{"date":{"year":2018,"month":8,"day":17},"pay":666410,"cons":5717049},
{"date":{"year":2018,"month":8,"day":16},"pay":435064,"cons":1587303},
{"date":{"year":2018,"month":8,"day":15},"pay":217724,"cons":51281},
{"date":{"year":2018,"month":8,"day":14},"pay":240684,"cons":43044}
]
}
a_dict = ({"date": {"year": 2011, "month": 2, "day": 2}, "pay": 810, "cons": 174})
with open('tbl.json') as f:
data = json.load(f)
dat = data.update(a_dict)
data.update(a_dict)
with open('tbl.json', 'w') as f:
json.dump(data, f)
Answer the question
In order to leave comments, you need to log in
a_dict = ({"date": {"year": 2011, "month": 2, "day": 2}, "pay": 810, "cons": 174}, )
with open('tbl.json') as f:
data = json.load(f)
data["values"] += list(a_dict)
with open('tbl.json', 'w') as f:
json.dump(data, f)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question