You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
json-builder is fully interoperable with json-parser:
charjson[] ="[ 1, 2, 3 ]";
json_settingssettings= {};
settings.value_extra=json_builder_extra; /* space for json-builder state */charerror[128];
json_value*arr=json_parse_ex(&settings, json, strlen(json), error);
/* Now serialize it again. */char*buf=malloc(json_measure(arr));
json_serialize(buf, arr);
printf("%s\n", buf);
[ 1, 2, 3 ]
Note that values created by or modified by json-builder must be freed with
json_builder_free instead of json_value_free, otherwise the memory of the
builder state will be leaked.
Modes
json_serialize_mode_multiline — Generate multi-line JSON, for example:
[
1,
2,
3
]
json_serialize_mode_single_line — Generate JSON on a single line, for example:
[ 1, 2, 3 ]
json_serialize_mode_packed — Generate JSON as tightly packed as possible, for example:
[1,2,3]
Options
json_serialize_opt_CRLF — use CR/LF (Windows) line endings
json_serialize_opt_pack_brackets — do not leave spaces around brackets (e.g. [ 1, 2 ] becomes [1, 2])
json_serialize_opt_no_space_after_comma — do not leave spaces after commas
json_serialize_opt_no_space_after_colon — do not leave spaces after colons (inside objects)
json_serialize_opt_use_tabs — indent using tabs instead of spaces when in multi-line mode
indent_size — the number of tabs or spaces to indent with in multi-line mode