From 2137d2f13310aca3cef6a0fc7735fdf4aac53e8c Mon Sep 17 00:00:00 2001 From: default Date: Thu, 3 Aug 2023 08:42:38 +0200 Subject: Backport from xs. --- xs_json.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'xs_json.h') 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) */ -- cgit v1.2.3