So I have a json file which looks something like this
{
"Version": "2.0",
"Description": "A description...",
"A": {
[...]
},
"B": {
"B.a": {
"B.a.a": {
"Value1": "It's value",
"Value2": "This value"
},
"B.a.1": {
"Value1": "Value x.a.1",
"Value2": "Value y.a.1"
},
"B.a.2": {
"Value1": "Value x.a.2",
"Value2": "Value y.a.2"
},
"B.a.3": {
"Value1": "Value x.a.3",
"Value2": "Value y.a.3"
},
"B.a.4": {
"Value1": "Value x.a.4",
"Value2": "Value y.a.4"
}
}
},
"C": {
[...]
}, ...
Now the rest of my code check if B.a.1 and all others are the values they should have, and if not it will modify it.
with open(file, 'r+') as test:
data = json.load(test)
for version in allAVersions:
data["B"]["B.a"][version['VersionNumber']]['Value1'] = newVersion['Value1'][version['VersionNumer']]['NewValue1']
with open(file, 'w') as test:
test.write(json.dumps(data, indent=4, sort_keys=True))
This works perfectly fine! But the problem is that it put "B" and all the nodes within it at the start of the file. How can I modify the file so that it stays exactly where it already was. That is, if B.a.1 - Value 1 get a new value then it just changes that value, and the format doesn't change.
Thanks for the help :)