Bug #4860

Format of numbers generated by fn:xml-to-json

Added by Michael Kay about 1 month ago. Updated 27 days ago.

In Progress
Saxon extensions
Start date:
Due date:
% Done:


Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:


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 28 days ago

  • Status changed from New to In Progress

I propose to provide an option on xml-to-json():

map{'number-format': '0000.0'}

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 27 days 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).

#3 Updated by Michael Kay 27 days ago

I've added a proposal for this extension, and a draft spec, for the 4.0 project. I've added test cases to the qt4cg/qt4tests repository.

Please register to edit this issue

Also available in: Atom PDF