jsoninfo: helpers: output an empty string when the string is null
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 7 Mar 2016 09:17:17 +0000 (10:17 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 7 Mar 2016 19:50:17 +0000 (20:50 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/jsoninfo/src/olsrd_jsoninfo_helpers.c

index fdcb27c..a10be53 100644 (file)
@@ -148,12 +148,20 @@ void abuf_json_boolean(struct autobuf *abuf, const char* key, bool value) {
 }
 
 void abuf_json_string(struct autobuf *abuf, const char* key, const char* value) {
+  const char * val;
+
   assert(abuf);
   assert(key);
 
+  if (!value) {
+    val = empty;
+  } else {
+    val = value;
+  }
+
   abuf_json_insert_comma(abuf);
   abuf_json_new_indent(abuf);
-  abuf_appendf(abuf, "\"%s\": \"%s\"", key, value);
+  abuf_appendf(abuf, "\"%s\": \"%s\"", key, val);
   entrynumber[currentjsondepth]++;
 }