yyjson icon indicating copy to clipboard operation
yyjson copied to clipboard

[FEAT] Generate minimal JSON5 result

Open CarterLi opened this issue 5 months ago • 0 comments

Is your feature request related to a problem? Please describe. We introduced JSON5 reading support in the last version, but we can't make use of JSON5 syntax when generating JSON string. It would be very useful when generating config file with less verbose JSON5 syntax.

Describe the solution you'd like Add write flag YYJSON_WRITE_MINIMAL_JSON5, which

  1. use unquoted keys if possible (start with an alpha char, doesn't contain white space or escaped codes, etc)
  2. use single quoted strings when meaningful. If the string contains " but not ', use single quoted string. Use double quoted string otherwise. (Should we add a flag that prefer ' over "?)
  3. use named escape codes if possible. YYJSON_WRITE_ESCAPE_UNICODE with additional escape codes introduced in JSON5 (\0, \e, etc). Prefer \xXX over \u00XX.

Describe alternatives you've considered N/A

Additional context N/A

CarterLi avatar Aug 19 '25 03:08 CarterLi