pyhocon icon indicating copy to clipboard operation
pyhocon copied to clipboard

Parsing error when loading JSON file containing quoted, multi-key/value dict.

Open enlightenalpha opened this issue 7 years ago • 3 comments

I have a HOCON file which contains many key values similar to the following:

value: "{\"critical\":\"0.00\",\"warning\":\"99.99\"}"

When trying to parse, I receive the following exception:

Virtualenvs/cloudera/lib/python2.7/site-packages/pyparsing.pyc

in parseString(self, instring, parseAll) 1630 else: 1631 # catch and re-raise exception from here, clears out pyparsing internal stack trace -> 1632 raise exc 1633 else: 1634 return tokens

ParseSyntaxException: Expected "}" (at char 32936), (line:893, col:74)

The file validates against several HOCON linters. Why are escaped double quotes not supported?

enlightenalpha avatar Nov 02 '17 21:11 enlightenalpha

Update - when I remove the escaped quotes, pyhocon is able to parse the file just fine. Question - why should I have to remove them? It's valid JSON/HOCON.

enlightenalpha avatar Nov 03 '17 13:11 enlightenalpha

Any ideas / thoughts on how to handle this or if this is expected behavior? As I mentioned, I can get around it by removing the escaped quotes, but this is a risky proposition as I'm ruining the integrity of the original values which leads to serialization errors.

enlightenalpha avatar Nov 16 '17 14:11 enlightenalpha

So, it looks like the problem centers around the fact that the value being parsed contains 2 comma delimited key:value pairs:

"{"warning":500,"critical":"never"}"

If I change it to: "{"warning":500}"

...the parser doesn't complain. However, this isn't the value I need to pass so defeats the purpose.

I see the same behavior with the following value:

"morphlines:[\n {\n id:common\n importCommands:["org.kitesdk.morphline.", "com.ngdata."]"

The parser does not like the comma delimited portion of the importCommands chunk, however this is all part of a value so I'm not sure why the parser is trying to process:

ParseSyntaxException: Expected "}" (at char 33173), (line:616, col:115)

enlightenalpha avatar Dec 08 '17 21:12 enlightenalpha