Apologies, I should have been less lazy :)

https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-xml-to-json


--
Tim A. Thompson (he, him)
Librarian for Applied Metadata Research
Yale University Library
www.linkedin.com/in/timathompson<http://www.linkedin.com/in/timathompson>
timat...@protonmail.com<mailto:timothy.thomp...@yale.edu>


From: Thompson, Timothy <timothy.thomp...@yale.edu>
Date: Sunday, December 10, 2023 at 1:22 PM
To: BaseX <basex-talk@mailman.uni-konstanz.de>
Subject: JSON number serialization
Hello,

Is it part of the spec that numbers in the “basic” JSON representation (of 7+ 
digits) be serialized using scientific notation? For example:

let $direct := <json type="object"><n type="number">1339029</n></json>
let $basic := <fn:map><fn:number key="n">1339029</fn:number></fn:map>
let $result := ($direct, $basic) ! serialize(., map {
    "method": "json", "json": map {
      "format": if (position() eq 1) {"direct"} else {"basic"}, "indent": "yes"
    }
  })
return $result

…produces two different results:

{
  "n":1339029
}
{
  "n":1.339029E6
}

I usually prefer working with the “basic” format, but the automatic conversion 
to scientific notation is inconvenient because the value is not easily castable 
as an xs:integer.

Thanks in advance,
Tim


--
Tim A. Thompson (he, him)
Librarian for Applied Metadata Research
Yale University Library
www.linkedin.com/in/timathompson<http://www.linkedin.com/in/timathompson>
timat...@protonmail.com<mailto:timothy.thomp...@yale.edu>

Reply via email to