musikinformatik / JSONlib

A JSON de- and encoder for SuperCollider
GNU General Public License v2.0
11 stars 0 forks source link

support for json5? #31

Open LFSaw opened 1 year ago

LFSaw commented 1 year ago

Thanks again for this wonderful add-on, I use it all the time :) I was wondering:

There's a (simple) extension to json called json5 that especially includes comments and is targeted towards human readablity. Might be worth looking into to support?

Example from the website:

{
  // comments
  unquoted: 'and you can quote me on that',
  singleQuotes: 'I can use "double quotes" here',
  lineBreaks: "Look, Mom! \
No \\n's!",
  hexadecimal: 0xdecaf,
  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
  positiveSign: +1,
  trailingComma: 'in objects', andIn: ['arrays',],
  "backwardsCompatible": "with JSON",
}

A more real-world example is this config file from the Chromium/Blink project.

capital-G commented 1 year ago

The completeness of the JSON standard is probably its best feature but also its worst as it does not allow to add features such as comments.

YAML on the other hand allows comments and revisions, but its implementation is also much more complex, see https://yaml.org/spec/1.2.2/ I have not checked but I would guess that the SuperCollider YAML decoder faces the same problems as the JSON decoder, mainly ignoring the data type of its scalars and use string for everything.

As we still rely on the internal parseJSON method and only extend it by trying to reconstruct the original data types we can not make up for the incompability of the SC JSON decoder to parse only valid JSON (or does it? have you checked it?). To make this work we would need to implement the JSON(5) decoder within sclang, which currently uses a CPP library to parse JSON/YAML files. The sclang implementation would be slower for sure (at least factor 10?) and memory inefficient for big JSON data structures.

So what to do? From a pragmatic perspective I would suggest

From a non-pragmatic perspective I would suggest

What would you prefer @LFSaw ?

telephon commented 1 year ago

https://github.com/supercollider/supercollider/issues/5988#issuecomment-1472220835