Skip to content
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

fn:xml-to-json: Amendments #1493

Open
ChristianGruen opened this issue Oct 10, 2024 · 3 comments · May be fixed by #1578
Open

fn:xml-to-json: Amendments #1493

ChristianGruen opened this issue Oct 10, 2024 · 3 comments · May be fixed by #1578
Assignees
Labels
Editorial Minor typos, wording clarifications, example fixes, etc. PR Pending A PR has been raised to resolve this issue XQFO An issue related to Functions and Operators

Comments

@ChristianGruen
Copy link
Contributor

Maybe I was too quick in waving through #1476 as I believe that the current version is a bit sketchy. It says:

An element $E named number is processed by copying the string value of $E to the output, making any changes that are necessary to ensure that the result is a valid JSON number. Such changes include:

  • Removing leading and trailing whitespace.
  • Removing a leading plus sign.
  • Removing redundant leading zero digits.
  • Adding a zero digit before or after a decimal point that is not preceded and followed by a digit.
  1. For input like X, we cannot ensure that it will be a valid JSON number, so I assume that the changed string needs to be validated before being output?
  2. “Removing redundant leading zero digits” may not consider negative number like -01.
  3. Does “Such changes include” imply that the list may not be comprehensive?

In many cases, the numbers to be output will be the result of an earlier json-to-xml conversion. If it is generated with XPath numbers, we shouldn’t encounter plus signs, redundant leading zeros etc. either, so I would suggest getting rid of all post-processing. We could simply say:

An element $E named number results in the output of the string value of the element if it is a valid JSON number. Otherwise, [FOJS0006] is raised.

If we do want to tweak the string value, we should provide a complete set of rules; maybe something like…

The string value of an element $E named number is modified by:

  • removing leading and trailing whitespace,
  • removing a single leading plus sign,
  • removing redundant leading zero digits, which are optionally preceded by a leading minus sign,
  • adding a zero digit before a decimal point that is not preceded by a digit, and
  • adding a zero digit after a decimal point that is not followed by a digit.

If the result is a valid JSON number, it is output. Otherwise, [FOJS0006] is raised.

…but that’s still fuzzy (for example, it lacks the explanation of what redundant zero digits are).

@ChristianGruen ChristianGruen added XQFO An issue related to Functions and Operators Editorial Minor typos, wording clarifications, example fixes, etc. labels Oct 10, 2024
@ChristianGruen
Copy link
Contributor Author

Adding a zero digit before or after a decimal point that is not preceded and followed by a digit.

I just wondered if a . input string should really be replaced by 0.0?
I think we should drop all cleanups.

@michaelhkay
Copy link
Contributor

Actually, I deliberately left the rules a bit fuzzy, because I wasn't 100% confident of getting them right. The key thing is that the result has to be valid JSON, and I gave a list of things you might need to do to ensure that; I worded it in such a way that if it turns out not to be a complete list of rules, the essential thing is that the result is valid JSON.

Note that there's already a constraint that the input must be a valid xs:double, so we don't have to deal with your example of .: the xs:double rules allow .1 and 1., but not .. We only have to deal with cases that are valid XML but not valid JSON.

I think we should drop all cleanups.

I disagree. If it's valid XML we should output valid JSON. That's what the function is for.

@ChristianGruen
Copy link
Contributor Author

Note that there's already a constraint that the input must be a valid xs:double

I see; this is helpful information. So I assume the idea is that the original string should be validated first to be further modified by the rules, which convert an xs:double value to a correct JSON number?

I disagree. If it's valid XML we should output valid JSON. That's what the function is for.

I fully agree – but I think we should only validate the original string, without adjusting it by rules that may partially be implementation-dependent.

@michaelhkay michaelhkay added the PR Pending A PR has been raised to resolve this issue label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Editorial Minor typos, wording clarifications, example fixes, etc. PR Pending A PR has been raised to resolve this issue XQFO An issue related to Functions and Operators
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants