-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Expecting property name enclosed in double quotes: line 3 column 4 (char 6)
caused by
param" : "value" ,
Expecting ':' delimiter: line 3 column 14 (char 16)
caused by
"param : "value" ,
Expecting value: line 3 column 14 (char 16)
caused by
"param" : value" ,
Invalid control character at: line 3 column 22 (char 24)
caused by
"param" : "value ,
Four different error messages - but the root cause is the same for all errors: a missing quote.
The JSON parser is not able to detect this properly, and for users (especially if they are not so much experienced) this is a mess.
In my opinion we cannot let the JSON parser do this job - reacting in a useful way on missing quotes.
So why not using other parser to support here? The Python internal lexical parser shlex is suitable to do this.
I suggest to implement an additional pre-check, e.g. in this way:
JSON = """
{
"param" : "value ,
"A" : 123 ,
"C" : "1 and 2 and ${param}",
"D" : "${param}"
}
"""
listLines = JSON.splitlines()
for sLine in listLines:
try:
listDummy = shlex.split(sLine)
except Exception as reason:
print()
print("[shlex exception]\n" + str(reason) + f"\nin line: '{sLine}'")
print()
sys.exit()
Every missing (single) quote will cause error messages like this:
[shlex exception]
No closing quotation
in line: ' "param" : "value ,'
This would be much more helpful for users.
Metadata
Metadata
Labels
Projects
Status