summaryrefslogtreecommitdiff
path: root/xs_json.h
diff options
context:
space:
mode:
authorGravatar default2023-08-03 08:42:38 +0200
committerGravatar default2023-08-03 08:42:38 +0200
commit2137d2f13310aca3cef6a0fc7735fdf4aac53e8c (patch)
tree69d426ca8e14ff509a9cdd94d443b81bf975e7a0 /xs_json.h
parentFixed a log message level. (diff)
downloadpenes-snac2-2137d2f13310aca3cef6a0fc7735fdf4aac53e8c.tar.gz
penes-snac2-2137d2f13310aca3cef6a0fc7735fdf4aac53e8c.tar.xz
penes-snac2-2137d2f13310aca3cef6a0fc7735fdf4aac53e8c.zip
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 @@
5#define _XS_JSON_H 5#define _XS_JSON_H
6 6
7xs_str *xs_json_dumps_pp(const xs_val *data, int indent); 7xs_str *xs_json_dumps_pp(const xs_val *data, int indent);
8int xs_json_dump_pp(const xs_val *data, int indent, FILE *f);
8#define xs_json_dumps(data) xs_json_dumps_pp(data, 0) 9#define xs_json_dumps(data) xs_json_dumps_pp(data, 0)
9xs_val *xs_json_loads(const xs_str *json); 10xs_val *xs_json_loads(const xs_str *json);
10 11
@@ -165,6 +166,19 @@ xs_str *xs_json_dumps_pp(const xs_val *data, int indent)
165} 166}
166 167
167 168
169int xs_json_dump_pp(const xs_val *data, int indent, FILE *f)
170/* dumps data into a file as JSON */
171{
172 xs *j = xs_json_dumps_pp(data, indent);
173
174 if (j == NULL)
175 return 0;
176
177 fwrite(j, strlen(j), 1, f);
178 return 1;
179}
180
181
168/** JSON loads **/ 182/** JSON loads **/
169 183
170/* this code comes mostly from the Minimum Profit Text Editor (MPDM) */ 184/* this code comes mostly from the Minimum Profit Text Editor (MPDM) */