-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serialize-json() bug - extra commas #7
Comments
This problem is caused by incorrect using of position() in function xqjson:serializeJSONObject. declare %private function xqjson:serializeJSONObject($e as element())
as xs:string*
{
"{",
$e/*/(
if(position() = 1) then () else ",",
'"', xqjson:escape-json-string(@name), '":',
xqjson:serializeJSONElement(.)
),
"}"
}; to this: declare %private function xqjson:serializeJSONObject($e as element())
as xs:string*
{
"{",
for $el at $pos in $e/* return
(
if($pos = 1) then () else ",",
'"', xqjson:escape-json-string($el/@name), '":',
xqjson:serializeJSONElement($el)
),
"}"
}; |
Wonderful! I'd be happy to accept a pull request with this fix. |
Thanks for the pull request, @Albicocca. After further testing with the test example in this issue, I realized that I need to apply your logic to |
Fixed by d193107 |
The
serialize-json()
function appears to be inserting extra commas in the result. Here's a reproducible test, using eXide in the latest revision from the eXist-db develop branch:This returns
'[1,[,2,3]]'
instead of the expected original input. Notice the extra comma preceding2
.The
parse-json()
function doesn't seem to be the cause of the problem, since$parsed
is correct here:So the problem as I see it is with the
serialize-json()
function.The text was updated successfully, but these errors were encountered: