summaryrefslogtreecommitdiff
path: root/xs_json.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-08-03 08:42:38 +0200
committerdefault <nobody@localhost>2023-08-03 08:42:38 +0200
commit2137d2f13310aca3cef6a0fc7735fdf4aac53e8c (patch)
tree69d426ca8e14ff509a9cdd94d443b81bf975e7a0 /xs_json.h
parentd455280705700cf75b4b7a59218cf48d4684ae68 (diff)
Backport from xs.
Diffstat (limited to 'xs_json.h')
-rw-r--r--xs_json.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/xs_json.h b/xs_json.h
index 388cfe0..d702a85 100644
--- a/xs_json.h
+++ b/xs_json.h
@@ -5,6 +5,7 @@
#define _XS_JSON_H
xs_str *xs_json_dumps_pp(const xs_val *data, int indent);
+int xs_json_dump_pp(const xs_val *data, int indent, FILE *f);
#define xs_json_dumps(data) xs_json_dumps_pp(data, 0)
xs_val *xs_json_loads(const xs_str *json);
@@ -165,6 +166,19 @@ xs_str *xs_json_dumps_pp(const xs_val *data, int indent)
}
+int xs_json_dump_pp(const xs_val *data, int indent, FILE *f)
+/* dumps data into a file as JSON */
+{
+ xs *j = xs_json_dumps_pp(data, indent);
+
+ if (j == NULL)
+ return 0;
+
+ fwrite(j, strlen(j), 1, f);
+ return 1;
+}
+
+
/** JSON loads **/
/* this code comes mostly from the Minimum Profit Text Editor (MPDM) */