[syslog-ng] [PATCH] json-parser: Change the way arrays are formatted

Gergely Nagy algernon at balabit.hu
Fri Mar 30 09:18:11 CEST 2012


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 at 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 at balabit.hu>
+ * Copyright (c) 2011-2012 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2011-2012 Gergely Nagy <algernon at 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




More information about the syslog-ng mailing list