base: Prettier JSON output / options

- Add flags for indenting with 2, 4, or 8 spaces, still defaulting to
   tabs if none of those are set.

 - Don't emit a newline before emitting scalar values in dicts.
This commit is contained in:
Nicolas Williams
2022-10-01 00:12:09 -05:00
parent c6a46f0c96
commit 03f06b9472
2 changed files with 47 additions and 19 deletions

View File

@@ -463,7 +463,11 @@ typedef enum heim_json_flags {
HEIM_JSON_F_STRICT = 31,
HEIM_JSON_F_CNULL2JSNULL = 32,
HEIM_JSON_F_TRY_DECODE_DATA = 64,
HEIM_JSON_F_ONE_LINE = 128
HEIM_JSON_F_ONE_LINE = 128,
/* The default is to indent with one tab */
HEIM_JSON_F_INDENT2 = 256,
HEIM_JSON_F_INDENT4 = 512,
HEIM_JSON_F_INDENT8 = 1024,
} heim_json_flags_t;
heim_object_t heim_json_create(const char *, size_t, heim_json_flags_t,