diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-18 14:09:01 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-21 11:38:06 +0200 |
commit | ff88195a710ec58190a75a2c71e90126e52a07ca (patch) | |
tree | dc19544deb76dc8cf4344824d969b93bb0952ccb /eval.c | |
parent | 79a43239abefb5b2733719e145b47d4278a3310d (diff) |
eval: don't escape slashes when outputting array or object JSON
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -1147,8 +1147,27 @@ ut_write_str(struct json_object *v) const char *p; size_t len; - p = v ? json_object_get_string(v) : ""; - len = json_object_is_type(v, json_type_string) ? json_object_get_string_len(v) : strlen(p); + switch (json_object_get_type(v)) { + case json_type_object: + case json_type_array: + p = json_object_to_json_string_ext(v, JSON_C_TO_STRING_NOSLASHESCAPE|JSON_C_TO_STRING_SPACED); + len = strlen(p); + break; + + case json_type_string: + p = json_object_get_string(v); + len = json_object_get_string_len(v); + break; + + case json_type_null: + p = ""; + len = 0; + break; + + default: + p = json_object_get_string(v); + len = strlen(p); + } fwrite(p, 1, len, stdout); } |