[PATCH] json-parser: Change the way arrays are formatted
Instead of parsing an array into key-value pairs where the key has a suffix of a dot, followed by the array index, make the key resemble the javascript array syntax: array[index]. This makes it more intuitive to reach into arrays, and also makes it easier to discover arrays when formatting back to JSON. Signed-off-by: Gergely Nagy <algernon@balabit.hu> --- modules/jsonparser/jsonparser.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/jsonparser/jsonparser.c b/modules/jsonparser/jsonparser.c index b362f49..44406da 100644 --- a/modules/jsonparser/jsonparser.c +++ b/modules/jsonparser/jsonparser.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 2011 BalaBit IT Ltd, Budapest, Hungary - * Copyright (c) 2011 Gergely Nagy <algernon@balabit.hu> + * Copyright (c) 2011-2012 BalaBit IT Ltd, Budapest, Hungary + * Copyright (c) 2011-2012 Gergely Nagy <algernon@balabit.hu> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published @@ -96,14 +96,13 @@ log_json_parser_process_single (struct json_object *jso, gint i, plen; g_string_assign (sb_string (key), obj_key); - g_string_append_c (sb_string (key), '.'); plen = sb_string (key)->len; for (i = 0; i < json_object_array_length (jso); i++) { g_string_truncate (sb_string (key), plen); - g_string_append_printf (sb_string (key), "%d", i); + g_string_append_printf (sb_string (key), "[%d]", i); log_json_parser_process_single (json_object_array_get_idx (jso, i), prefix, sb_string (key)->str, msg); -- 1.7.9
On Fri, 2012-03-30 at 09:18 +0200, Gergely Nagy wrote:
Instead of parsing an array into key-value pairs where the key has a suffix of a dot, followed by the array index, make the key resemble the javascript array syntax: array[index].
This makes it more intuitive to reach into arrays, and also makes it easier to discover arrays when formatting back to JSON.
Signed-off-by: Gergely Nagy <algernon@balabit.hu> ---
Applied, thanks. NOTE: you might want to get rid off those g_string_printf() calls. Those are _slow_. -- Bazsi
Balazs Scheidler <bazsi@balabit.hu> writes:
On Fri, 2012-03-30 at 09:18 +0200, Gergely Nagy wrote:
Instead of parsing an array into key-value pairs where the key has a suffix of a dot, followed by the array index, make the key resemble the javascript array syntax: array[index].
This makes it more intuitive to reach into arrays, and also makes it easier to discover arrays when formatting back to JSON.
Signed-off-by: Gergely Nagy <algernon@balabit.hu> ---
Applied, thanks.
NOTE: you might want to get rid off those g_string_printf() calls. Those are _slow_.
It's on my TODO list, but I'm saving these for times when I need something quick & easy to fix. -- |8]
participants (2)
-
Balazs Scheidler
-
Gergely Nagy