Project

Profile

Help

What liberal options does Saxon implement when parsing JSON?

Added by Martin Honnen almost 7 years ago

http://saxonica.com/html/documentation/functions/fn/json-to-xml.html explains that "The parsing options recognized are 'liberal':true()|false(), ..." but it does not explain what Saxon allows when @map { 'liberal' : true() }@ is used. Is there some way to have Saxon allow/parse unquoted property names in JSON literals, like in

let $json-input as xs:string := '{ foo : 1}'
return json-to-xml($json-input, map { 'liberal' : true() })

? BaseX parses that into



  1

while Saxon 9.8 gives me a FOJS0001 which I understand is fine as far as the spec is concerned. But I would like to know which liberal parsing Saxon supports with liberal being set to true.


Replies (4)

Please register to reply

RE: What liberal options does Saxon implement when parsing JSON? - Added by Martin Honnen almost 7 years ago

So I tried to read the source of https://dev.saxonica.com/repos/archive/opensource/latest9.8/hej/net/sf/saxon/ma/json/JsonParser.java and it seems the @liberal@ option currently is allowing а trailing comma in object and array literals but has no liberal treatment for object property names. Тhere also seems some changes in parsing number literals and escape sequences in strings.

It would be nice if http://saxonica.com/html/documentation/functions/fn/json-to-xml.html explains what the @'liberal': true()@ option means.

RE: What liberal options does Saxon implement when parsing JSON? - Added by Michael Kay almost 7 years ago

From a quick look at the code, when liberal is set:

  • We are more flexible about the format of numeric literals, e.g. leading plus signs or empty fractional parts allowed

  • we allow and ignore trailing commas within [] and {}

  • we allow invalid escape sequences.

We should document this.

    (1-4/4)

    Please register to reply