json-c uses the json_object structure to store a json representation. This structure is marked typedef but I will always write struct, for clarity’s sake.
2 functions exist to print the json_object structures:
json_object_to_json_string(obj) is in fact a call to json_object_to_json_string_ext(obj, JSON_C_TO_STRING_SPACED).
The flag attribute of json_object_to_json_string_ext() are:
JSON_C_TO_STRING_PLAIN
JSON_C_TO_STRING_SPACED
JSON_C_TO_STRING_PRETTY
JSON_C_TO_STRING_NOZERO
Those flags can be combined using the | operator.
Example’s source code:
Example’s output:
One thing worth noting, the " character is escaped for security reasons.