I am writing a json file to a key value properties file:
Json Example:
{
"id":"0",
"meta":"down",
"type":"1",
"direction":"0",
"interval":"1800"
}
and need to write the file like below(need to match the indentation):
id = 0
meta = down
type = 1
direction = 0
interval = 1800
Now, after dumping the json, I am replacing texts, which works fine. But I am not able to get the proper indentation. Below is my code and output:
def updateConfigFile(filename):
with open(filename, 'U') as f:
newText=f.read()
while ':' in newText:
newText=newText.replace(':', ' = ')
while ',' in newText:
newText=newText.replace(',', ' ')
with open(filename, "w") as f:
f.write(newText)
Output:
direction = 0
stallTimeout = 60
description = down
rampTime = 4
deepDepth = 14
deepWindow = 5
id = 1
How can I achieve proper indentation? Thanks