summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib.c24
-rw-r--r--stream.h1
-rw-r--r--tests/010/json.tl29
3 files changed, 40 insertions, 14 deletions
diff --git a/lib.c b/lib.c
index 32b701a7..8b0ce7e9 100644
--- a/lib.c
+++ b/lib.c
@@ -14897,7 +14897,7 @@ static void out_json_rec(val obj, val out, struct json_opts jo,
int force_br = 0;
val iter, next;
- if (!jo.flat && jo.fmt == json_fmt_standard) {
+ if (jo.fmt == json_fmt_standard) {
put_string(lit("{\n"), out);
save_indent = inc_indent_abs(out, two);
} else {
@@ -14919,7 +14919,7 @@ static void out_json_rec(val obj, val out, struct json_opts jo,
}
out_json_rec(v, out, jo, ctx);
- if (!jo.flat && jo.fmt == json_fmt_standard) {
+ if (jo.fmt == json_fmt_standard) {
if ((next = cdr(iter)) != 0)
put_string(lit(",\n"), out);
else
@@ -14941,7 +14941,7 @@ static void out_json_rec(val obj, val out, struct json_opts jo,
int force_br = 0;
val iter, next;
- if (!jo.flat && jo.fmt == json_fmt_standard) {
+ if (jo.fmt == json_fmt_standard) {
put_string(lit("[\n"), out);
save_indent = inc_indent_abs(out, two);
} else {
@@ -14953,7 +14953,7 @@ static void out_json_rec(val obj, val out, struct json_opts jo,
val elem = car(iter);
next = cdr(iter);
out_json_rec(elem, out, jo, ctx);
- if (!jo.flat && jo.fmt == json_fmt_standard) {
+ if (jo.fmt == json_fmt_standard) {
if (next)
put_string(lit(",\n"), out);
else
@@ -14990,7 +14990,7 @@ static void out_json_rec(val obj, val out, struct json_opts jo,
val elem;
seq_iter_init(self, &si, obj);
- if (!jo.flat && jo.fmt == json_fmt_standard) {
+ if (jo.fmt == json_fmt_standard) {
put_string(lit("[\n"), out);
save_indent = inc_indent_abs(out, two);
} else {
@@ -15002,7 +15002,7 @@ static void out_json_rec(val obj, val out, struct json_opts jo,
val nxelem;
int more = seq_get(&si, &nxelem);
out_json_rec(elem, out, jo, ctx);
- if (!jo.flat && jo.fmt == json_fmt_standard) {
+ if (jo.fmt == json_fmt_standard) {
if (more)
put_string(lit(",\n"), out);
else
@@ -15032,7 +15032,7 @@ static void out_json_rec(val obj, val out, struct json_opts jo,
us_hash_iter_init(&hi, obj);
- if (!jo.flat && jo.fmt == json_fmt_standard) {
+ if (jo.fmt == json_fmt_standard) {
put_string(lit("{\n"), out);
save_indent = inc_indent_abs(out, two);
} else {
@@ -15053,14 +15053,14 @@ static void out_json_rec(val obj, val out, struct json_opts jo,
put_char(chr(':'), out);
}
out_json_rec(v, out, jo, ctx);
- if (!jo.flat && jo.fmt == json_fmt_standard) {
+ if (jo.fmt == json_fmt_standard) {
if ((next = hash_iter_next(&hi)) != 0)
put_string(lit(",\n"), out);
else
put_char(chr('\n'), out);
} else if ((next = hash_iter_next(&hi)) != 0) {
put_char(chr(','), out);
- if (!jo.flat && jo.fmt == json_fmt_standard)
+ if (jo.fmt == json_fmt_standard)
put_char(chr('\n'), out);
else if (width_check(out, nil))
force_br = 1;
@@ -15080,7 +15080,7 @@ static void out_json_rec(val obj, val out, struct json_opts jo,
int force_br = 0;
int first = 1;
- if (!jo.flat && jo.fmt == json_fmt_standard) {
+ if (jo.fmt == json_fmt_standard) {
put_string(lit("{\n"), out);
save_indent = inc_indent_abs(out, two);
@@ -15164,7 +15164,6 @@ static void out_json(val op, val obj, val out, struct strm_ctx *ctx)
val type = cdr(lookup_var(nil, print_json_type_s));
struct json_opts jo = {
if3(jfsym == standard_k, json_fmt_standard, json_fmt_default),
- 0,
type != nil
};
if (op == sys_qquote_s)
@@ -15869,8 +15868,7 @@ val put_json(val obj, val stream_in, val flat_in)
val jfsym = cdr(lookup_var(nil, print_json_format_s));
val type = cdr(lookup_var(nil, print_json_type_s));
struct json_opts jo = {
- if3(jfsym == standard_k, json_fmt_standard, json_fmt_default),
- flat != nil,
+ if3(jfsym == standard_k && !flat, json_fmt_standard, json_fmt_default),
type != nil
};
uw_simple_catch_begin;
diff --git a/stream.h b/stream.h
index a2a25073..a0042933 100644
--- a/stream.h
+++ b/stream.h
@@ -141,7 +141,6 @@ enum json_fmt {
struct json_opts {
enum json_fmt fmt : 4;
- unsigned flat : 1;
unsigned type : 1;
};
diff --git a/tests/010/json.tl b/tests/010/json.tl
index b7117d8a..57c9a8c5 100644
--- a/tests/010/json.tl
+++ b/tests/010/json.tl
@@ -207,3 +207,32 @@
(get-json "0") 0.0
(get-json "12345") 12345.0
(get-json "12345678900000000000000000") 1.23456789E25)
+
+(let ((obj #H(() ("a" #(1 2 3))
+ ("b" #H(() ("c" "d")
+ ("e" t) ("f" nil) ("g" #(4 5 6)))))))
+ (mtest
+ (tojson obj) "{\"a\":[1,2,3],\"b\":{\"c\":\"d\",\"f\":false,\"g\":[4,5,6],\"e\":true}}"
+ (tojson obj t) "{\"a\":[1,2,3],\"b\":{\"c\":\"d\",\"f\":false,\"g\":[4,5,6],\"e\":true}}"
+ (let ((*print-json-format* :standard))
+ (tojson obj))
+ "{\n \
+ \ \"a\" : [\n\
+ \ 1,\n\
+ \ 2,\n\
+ \ 3\n\
+ \ ],\n\
+ \ \"b\" : {\n\
+ \ \"c\" : \"d\",\n\
+ \ \"f\" : false,\n\
+ \ \"g\" : [\n\
+ \ 4,\n\
+ \ 5,\n\
+ \ 6\n\
+ \ ],\n\
+ \ \"e\" : true\n\
+ \ }\n\
+ }"
+ (let ((*print-json-format* :standard))
+ (tojson obj t))
+ "{\"a\":[1,2,3],\"b\":{\"c\":\"d\",\"f\":false,\"g\":[4,5,6],\"e\":true}}"))