From 9d99b9a71a24c6863b1a9b23e8d8060548ae4ff0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 31 May 2021 23:48:31 -0700 Subject: 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. --- lib.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'lib.c') 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); } -- cgit v1.2.3