When convert the properties to JSON it added extra backslash in ASCII character, How to avoid this, see the code below
Input File (sample.properties)
property.key.CHOOSE=\u9078\u629e
Code
import json
def convertPropertiesToJson(fileName, outputFileName, sep='=', comment_char='#'):
props = {}
with open(fileName, "r") as f:
for line in f:
l = line.strip()
if l and not l.startswith(comment_char):
innerProps = {}
keyValueList = l.split(sep)
key = keyValueList[0].strip()
keyList = key.split('.')
value = sep.join(keyValueList[1:]).strip()
if keyList[1] not in props:
props[keyList[1]] = {}
innerProps[keyList[2]] = value
props[keyList[1]].update(innerProps)
with open(outputFileName, 'w') as outfile:
json.dump(props, outfile)
convertPropertiesToJson("sample.properties", "sample.json")
Output: (sample.json)
{"key": {"CHOOSE": "\\u9078\\u629e"}}
Expected Result:
{"key": {"CHOOSE": "\u9078\u629e"}}