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

Support converting JSON5 comments to JSON object fields #7

Open
aSemy opened this issue Dec 22, 2021 · 1 comment
Open

Support converting JSON5 comments to JSON object fields #7

aSemy opened this issue Dec 22, 2021 · 1 comment

Comments

@aSemy
Copy link
Collaborator

aSemy commented Dec 22, 2021

Presently comments are discarded when reading data and and writing data out. This allows for full compatibility with plain-JSON, but it would be nice if comments were handled.

In plain-JSON a common workaround is to use //

{
  "//": "comment",
  "example": "value"
}

If comments occur within JSON5-objects this convention could be formalised for JSON5<->plain-JSON mapping. JSON5 comments would be converted to and from String-JsonPrimitives with a key of // (this would need to be unique)..

{
  // comment
  "example": "value"
}

When comments are not easily mapped to an object value (they're in arrays, or outside of an object) I'm not sure what can be done.

@aSemy aSemy changed the title Support comments Support converting JSON5 comments to JSON object fields Dec 22, 2021
@astynax
Copy link

astynax commented Jan 11, 2022

Nice idea!
What do you think about preserving of the original place of comment?

{
  // Here is
  // a comment for "a"
  "a": 42
  // and a comment for "b"
  "b": false
}

can become

{
  "//\"a\"": ["Here is", "a comment for \"a\""],
  "a": 42,
  "//\"b\"": ["and a comment for \"b\""],
  "b": false
}

Such "markup" will protect against of merging all the comments into a single key or from the "the last value wins" situation.

And, yes, it looks a bit ugly :(

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