JSON restrictions can be easily solved
fsmMLK opened this issue · comments
FYI, you can easily fix JSON's input format limitation (double quotes and last comma) with the following code. It loads the problematic JSON contents (already in a string) using yaml (json and yaml are compatible) and dumps it back to another string using json module. The new string has double quotes everywhere and eliminates the exceeding comma.
The function below fixes the problem.
import yaml
import json
def fixQuotes(inputString):
# fix double quotes in the input file. opening with yaml and dumping with json fix the issues.
yamlCode = yaml.load(inputString, Loader=yaml.FullLoader)
fixedString = json.dumps(yamlCode, indent=4)
return fixedString
Thanks, that sounds like a reasonable solution. Have you used it yourself in projects? Should be rather robust, right?