Use dumps to save json

main
Bob Mottram 2019-11-23 10:20:30 +00:00
parent 96c56491eb
commit ac2ab89aa6
2 changed files with 4 additions and 3 deletions

View File

@ -1635,7 +1635,7 @@ def testSaveLoadJson():
print('testSaveLoadJson')
testJson={
"param1": 3,
"param2": "test"
"param2": '"Crème brûlée यह एक परीक्षण ह"'
}
testFilename='/tmp/.epicyonTestSaveLoadJson.json'
if os.path.isfile(testFilename):
@ -1647,7 +1647,7 @@ def testSaveLoadJson():
assert testLoadJson.get('param1')
assert testLoadJson.get('param2')
assert testLoadJson['param1']==3
assert testLoadJson['param2']=="test"
assert testLoadJson['param2']=='"Crème brûlée यह एक परीक्षण ह"'
os.remove(testFilename)
def runAllTests():

View File

@ -10,6 +10,7 @@ import os
import time
import shutil
import datetime
import json
import commentjson
def saveJson(jsonObject: {},filename: str) -> bool:
@ -19,7 +20,7 @@ def saveJson(jsonObject: {},filename: str) -> bool:
while tries<5:
try:
with open(filename, 'w') as fp:
commentjson.dump(jsonObject, fp, indent=2, sort_keys=False)
fp.write(json.dumps(jsonObject))
return True
except:
print('WARN: saveJson '+str(tries))