JSON number serialization
Sunday, 10 December 2023 · 2 messages
TT
Thompson, Timothy10 Dec 2023 19:22 #
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> timathom at protonmail.com<mailto:timothy.thompson at yale.edu>
TT
Thompson, Timothy10 Dec 2023 19:30 #
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> timathom at protonmail.com<mailto:timothy.thompson at yale.edu>
Quoted text · Thompson, Timothy · 30 lines
From: Thompson, Timothy <timothy.thompson at yale.edu> Date: Sunday, December 10, 2023 at 1:22 PM To: BaseX <basex-talk at 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> timathom at protonmail.com<mailto:timothy.thompson at yale.edu>
Written for BaseX 10.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery