summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-31 23:48:31 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-31 23:48:31 -0700
commit9d99b9a71a24c6863b1a9b23e8d8060548ae4ff0 (patch)
tree5dd966f97b24e689e01c7301f378823eef73c008
parentf311b6ca089954675e745ad9212209ca8cf23be2 (diff)
downloadtxr-9d99b9a71a24c6863b1a9b23e8d8060548ae4ff0.tar.gz
txr-9d99b9a71a24c6863b1a9b23e8d8060548ae4ff0.tar.bz2
txr-9d99b9a71a24c6863b1a9b23e8d8060548ae4ff0.zip
json: turn on indentation.
* lib.c (put_json): Turn on indentation if the flat argument doesn't suppress it, and the stream is not in forced-off indentation mode. (tojson): Retarget to put_json, so we don't have to repeat this logic.
-rw-r--r--lib.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/lib.c b/lib.c
index 1989bf0c..11ad76b5 100644
--- a/lib.c
+++ b/lib.c
@@ -13473,15 +13473,12 @@ val tostringp(val obj)
val put_json(val obj, val stream_in, val flat)
{
val stream = default_arg(stream_in, std_output);
-
- if (default_null_arg(flat)) {
- out_json_rec(obj, stream, 0);
- } else {
- val imode = set_indent_mode(stream, num_fast(indent_foff));
- out_json_rec(obj, stream, 0);
- set_indent_mode(stream, imode);
- }
-
+ val imode = if3(default_null_arg(flat),
+ set_indent_mode(stream, num_fast(indent_foff)),
+ test_set_indent_mode(stream, num_fast(indent_off),
+ num_fast(indent_data)));
+ out_json_rec(obj, stream, 0);
+ set_indent_mode(stream, imode);
return t;
}
@@ -13495,9 +13492,7 @@ val put_jsonl(val obj, val stream, val flat)
val tojson(val obj, val flat)
{
val ss = make_string_output_stream();
- if (default_null_arg(flat))
- set_indent_mode(ss, num_fast(indent_foff));
- out_json_rec(obj, ss, 0);
+ put_json(obj, ss, flat);
return get_string_from_stream(ss);
}