Project

Profile

Help

xml-to-json Exponential notation of integers

Added by Greg Knittl about 8 years ago

I'm using json-to-xml and xml-to-json to transform json to json. The json contains 14 digit timestamps which are simply 14 decimal digit numbers. json-to-xml preserves them as 14 decimal digits. However xml-to-json converts them to exponential notation. This appears to be perfectly valid under the json spec. xml-to-json retains all the digits so it retains full precision. jq (json query) pretty print will convert them back to regular digits. There is no defect but it just seems like an overly complicated way for xml-to-json to output an integer. I'm running Saxon HE 9.7.0.4 with java version "1.7.0_95" OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.12.04.2) OpenJDK Server VM (build 24.95-b01, mixed mode) in case that matters.

p.s. thanks so much for bring the power of XSLT to bear on transforming JSON. I find it ironic that JSON seems to look down on XML yet can't get their act together to provide native template based transforms.


Replies (3)

Please register to reply

RE: xml-to-json Exponential notation of integers - Added by Michael Kay about 8 years ago

The specification states that the conversion must convert the supplied value to an xs:double and then use the standard conversion of xs:double to string. I'm not sure I recall the reasoning but at least it's reusing specifications (and therefore code) from other parts of the spec. Anyway, Saxon is simply doing what the spec says it should.

If you're interested in transformations applied to JSON you might like to look at the examples in the paper I published this year at XML Prague.

RE: xml-to-json Exponential notation of integers - Added by Mike Banks about 8 years ago

Is there any chance that xml-to-json could have an option to show integers "as entered"?

RE: xml-to-json Exponential notation of integers - Added by Michael Kay about 8 years ago

You'll have to raise that as a request against the spec (use the W3C bugzilla site)

    (1-3/3)

    Please register to reply