ibireme / yyjson

The fastest JSON library in C
https://ibireme.github.io/yyjson/doc/doxygen/html/
MIT License
3.04k stars 262 forks source link

custom indent, for example, 2 space indent. #99

Closed loynoir closed 1 year ago

loynoir commented 1 year ago

Is your feature request related to a problem? Please describe. Custom indent, for example, 2 space indent.

Describe the solution you'd like Like js

JSON.stringify(foobar,null,2)

Or like jansson

json_dumps(root, (size_t)JSON_INDENT(2));

Describe alternatives you've considered YYJSON_WRITE_PRETTY_TWO_SPACES

Additional context

ibireme commented 1 year ago

I have added the YYJSON_WRITE_PRETTY_TWO_SPACES flag: https://github.com/ibireme/yyjson/commit/eff456db72844839f248cdaef5b20ae58669b4c4. It doesn't affect performance in benchmark tests.

Supporting variable length indent may cause some performance degradation, so I have not implemented it.