summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index e1879df6..75cbc739 100644
--- a/lib.c
+++ b/lib.c
@@ -13454,6 +13454,27 @@ val tostringp(val obj)
return get_string_from_stream(ss);
}
+val tojson(val obj, val flat)
+{
+ if (consp(obj) && eq(car(obj), json_s)) {
+ val ss = make_string_output_stream();
+ if (default_null_arg(flat))
+ set_indent_mode(ss, num_fast(indent_foff));
+ obj_print(obj, ss, nil);
+ return get_string_from_stream(ss);
+ } else {
+ val json = cons(json_s, cons(quote_s, cons(obj, nil)));
+ val ss = make_string_output_stream();
+ if (default_null_arg(flat))
+ set_indent_mode(ss, num_fast(indent_foff));
+ obj_print(json, ss, nil);
+ rcyc_pop(&json);
+ rcyc_pop(&json);
+ rcyc_pop(&json);
+ return get_string_from_stream(ss);
+ }
+}
+
val display_width(val obj)
{
if (stringp(obj)) {