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

Serialize functions: consistency #760

Open
ChristianGruen opened this issue Oct 18, 2023 · 2 comments
Open

Serialize functions: consistency #760

ChristianGruen opened this issue Oct 18, 2023 · 2 comments
Labels
Enhancement A change or improvement to an existing feature Serialization An issue related to the Serialization spec XQFO An issue related to Functions and Operators

Comments

@ChristianGruen
Copy link
Contributor

We should be more ambitious about ensuring consistency when serializing data back to its original representation, and how to achieve it. This is the status quo:

Format Serialize Function Parse Function
XML fn:serialize($input) fn:parse-xml
JSON fn:serialize($input, map { 'method': 'json' }) fn:parse-json
JSON fn:xml-to-json($input) fn:json-to-xml
XHTML fn:serialize($input, map { 'method': 'xhtml' }) fn:parse-html
HTML fn:serialize($input, map { 'method': 'html' }) fn:parse-html
CSV still missing fn:parse-csv and variants

In BaseX, the XML created by fn:json-to-xml can already be serialized back to JSON as follows (related: #759):

serialize(
  <map xmlns="http://www.w3.org/2005/xpath-functions">
    <number key="A">1</number>
  </map>,
  map { 'method': 'json', 'json': map { 'format': 'basic' }
})

For CSV, we’ve introduced a CSV serialization method that supports all CSV flavors we support (see CSV Module for more details):

serialize(
  <map xmlns="http://www.w3.org/2005/xpath-functions">
    <number key="A">1</number>
  </map>,
  map { 'method': 'csv', 'csv': map { 'format': 'direct' }
})

Related (parse functions): #748

@ChristianGruen ChristianGruen added XQFO An issue related to Functions and Operators Enhancement A change or improvement to an existing feature Serialization An issue related to the Serialization spec labels Oct 18, 2023
@ndw
Copy link
Contributor

ndw commented Jun 4, 2024

What is the actual proposal?

@ChristianGruen
Copy link
Contributor Author

Greetings to Prague… The proposal could be twofold:

  1. introduce a csv serialization method;
  2. add a serialization parameter for the existing json method to serialize the result of fn:json-to-xml back to JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A change or improvement to an existing feature Serialization An issue related to the Serialization spec XQFO An issue related to Functions and Operators
Projects
None yet
Development

No branches or pull requests

2 participants