Skip to content

[FEAT] Generate minimal JSON5 result #224

@CarterLi

Description

@CarterLi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions