From d17629aeaf6129f00780f71036248e6715331ca0 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Mon, 20 Oct 2025 19:32:21 +0200 Subject: [PATCH] json_encode fixes --- base/sources/iron_json.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/base/sources/iron_json.c b/base/sources/iron_json.c index b6947e4e..ab4636f6 100644 --- a/base/sources/iron_json.c +++ b/base/sources/iron_json.c @@ -310,6 +310,8 @@ any_map_t *json_parse_to_map(char *s) { static char *encoded; static int keys; +static int array_nest = -1; +static int array_length[16]; void json_encode_begin() { encoded = "{"; @@ -396,15 +398,24 @@ void json_encode_bool(char *k, bool b) { } void json_encode_begin_array(char *k) { + array_nest++; + array_length[array_nest] = 0; json_encode_key(k); encoded = string_join(encoded, "["); } void json_encode_end_array() { + array_nest--; encoded = string_join(encoded, "]"); } void json_encode_begin_object() { + if (array_nest > -1) { + if (array_length[array_nest] > 0) { + encoded = string_join(encoded, ","); + } + array_length[array_nest]++; + } keys = 0; encoded = string_join(encoded, "{"); }