Format of numbers generated by fn:xml-to-json
A customer writes saying they have a JSON application where the JSON parser can't handle numbers in scientific notation. I've heard the same problem before. We should add an option to the options parameter to disable scientific notation for number values.
#1 Updated by Michael Kay 4 months ago
- Status changed from New to In Progress
I propose to provide an option on xml-to-json():
where number-format follows the rules of the picture argument to the fn:format-number() function.
A similar option on the JSON serializer is also appropriate.
#2 Updated by Michael Kay 4 months ago
Having second thoughts on the design here. Making the property a format-number picture implies that we will still start by doing string-to-double conversion on the
<number> element, which may not always be wanted. For example, it doesn't allow users to "stretch" what is allowed to appear in the
<number> element (e.g. some might want to use a European-format number with a "," as the decimal separator, or to have more decimal digits than
xs:double can accommodate.) And it restricts the reformatting that is possible, for example it doesn't give you the opportunity to output `"INF" or "NaN" (as JSON strings) rather than rejecting these as errors.
So I'm going to try an alternative design, where we add an option
number-formatter whose value is a
function(xs:string) as xs:string, which takes the number as it appears in the XML, and outputs the number as it will appear in the JSON (with no constraint that the result is valid JSON).
Please register to edit this issue