A
A
a2019-09-26 20:36:26
Python
a, 2019-09-26 20:36:26

How to add a line to JSON?

How to add data to a line, and not to the end or beginning.
For example:
JSON:

"Users":{

}

You need to add data to users.
And when writing to JSON, a line is written on how to make the JSON file readable.
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2019-09-26
@MZOK

Read, change key value, write back.

data = json.load(file)
data['Users'] = new_data
json.dump(data, file)

If by "readable" you mean indents, then apply indent to json.dump
json.dump(data, file, indent=4)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question