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

Explore different characters for XML attributes #74

Open
ghost opened this issue Nov 1, 2019 · 4 comments
Open

Explore different characters for XML attributes #74

ghost opened this issue Nov 1, 2019 · 4 comments

Comments

@ghost
Copy link

ghost commented Nov 1, 2019

When it comes to XML attributes, XQ prepends with @:

$ cat sun.xml
<sunday before="monday"/>

$ xq . < sun.xml
{
  "sunday": {
    "@before": "monday"
  }
}

my issue is that with YAML @ requires quoting:

$ xq . < sun.xml | yq -y .
sunday:
  '@before': monday

Other characters are available that dont require quoting, for example:

$ cat sun.json
{
  "sunday": {
    "$before": "monday"
  }
}

$ yq -y . < sun.json
sunday:
  $before: monday

Here are others:

- ( ) . / ; ? \ ^ _ ~ + < =

To counter myself, some would point to this page:

https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html

Which is referenced by multiple repos:

Further as @ represents the "at sign", it is similar to "attribute" and so
easy to remember. However I would make a couple of points. The xml.com page
above has no mention of YAML, and as such I think its validity is weakened in
regards to a YAML repo. Futher, I think it would be helpful to use a character
that "plays nice" or is the "least bad" across XML, JSON and YAML, and
that is not the @ character.

Ideally I would say the default should be changed to $ or similar, but if the
default stays and an option is added to XQ, that would be acceptable as well. I did find these documents in support of $ character:

@kislyuk
Copy link
Owner

kislyuk commented Nov 6, 2019

Thanks for the suggestion. I have a hard time believing that there are a lot of use cases for converting XML to YAML. I'd probably be OK with adding an option for configuring this (I'm not OK with changing the default).

@ghost
Copy link
Author

ghost commented Nov 6, 2019

@kislyuk thanks, I dont do a lot of XML => YAML conversion, but I noticed that XML can be more expressive since it has attributes. JSON and YAML dont, but you can fake them in different ways. It is interesting to see how different people represent XML as JSON or YAML.

@ksridhar
Copy link

ksridhar commented Mar 31, 2022

This is with reference to #74 (comment)
Pardon me for asking this but were command line options added to override the "@" and "#" prefixes in the output of xq ?
i would love to have this as i would want to use the output json in json-ld where "@" is used as a 'directive' prefix.
i did'nt see these options in the cli documentation and hence this question.

@kislyuk
Copy link
Owner

kislyuk commented Mar 31, 2022

Hi @ksridhar - there is no command line option to customize this behavior. PRs are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants