I need to get the complete json and save it in a file in the same
position.
You shouldn't rely on position to update a file containing JSON.
First of all, it would be wise to separate the configuration you seem to store in JSON from the actual code.
So let's say you have a file containing JSON:
config.json
{
"window": {
"innerHeight": 886,
"innerWidth": 1280
},
"window.screen": {
"availWidth": 1280,
"availTop": 0,
"availHeight": 1024,
"availLeft": 0
},
"window.navigator": {
"oscpu": "Windows NT 6.3; WOW64",
"product": "Gecko",
"vendor": "",
"buildID": "20140923175406",
"appName": "Netscape",
"appCodeName": "Mozilla",
"productSub": "20100101",
"plugins": {
"1": {
"application/sdp": {
"type": "application/sdp",
"description": "Playing SDP-files",
"suffixes": "sdp"
},
"name": "QuickTime Plug-in 7.7.5",
"filename": "npqtplugin.dll",
"0": {
"type": "application/sdp",
"description": "Playing SDP-files",
"suffixes": "sdp"
},
"length": 1,
"version": "7.7.7.5",
"description": "The QuickTime Plugin allows you to view a wide variety of multimedia content in Web pages. For more information, visit the QuickTime Web site."
},
"0": {
"1": {
"type": "application/futuresplash",
"description": "FutureSplash movie",
"suffixes": "spl"
},
"0": {
"type": "application/x-shockwave-flash",
"description": "Adobe Flash movie",
"suffixes": "swf"
},
"length": 2,
"version": "12.0.0.43",
"name": "Shockwave Flash",
"application/futuresplash": {
"type": "application/futuresplash",
"description": "FutureSplash movie",
"suffixes": "spl"
},
"application/x-shockwave-flash": {
"type": "application/x-shockwave-flash",
"description": "Adobe Flash movie",
"suffixes": "swf"
},
"filename": "NPSWF32_12_0_0_43.dll",
"description": "Shockwave Flash 12.0 r.43"
},
"length": 2,
"Shockwave Flash": {
"application/futuresplash": {
"description": "FutureSplash movie",
"suffixes": "spl"
},
"description": "Shockwave Flash 12.0 r.43",
"application/x-shockwave-flash": {
"description": "Adobe Flash movie",
"suffixes": "swf"
},
"filename": "NPSWF32_12_0_0_43.dll",
"version": "12.0.0.43",
"name": "Shockwave Flash"
}
},
"userAgent": "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0.3",
"language": "en",
"appVersion": "5.0 (Windows)",
"platform": "x86",
"vendorSub": ""
}
}
What you'll need to do to update the JSON stored in the file is to read the file, use json.loads to load the JSON into a python dict, update anything you might want and save the output of json.dumps with the updated keys and values to the same file. So you'll end up having something like this somewhere in your code:
import json
with open('prueba.json', 'r') as f:
config = json.loads(f.read())
with open('prueba.json', 'w') as f:
# Here I update window settings as an example
config['window']['innerHeight'] = 1440
config['window']['innerWidth'] = 900
f.write(json.dumps(config))