diff --git a/lib/clixon/clixon_json.h b/lib/clixon/clixon_json.h
index 0ca368ac..0a3b9952 100644
--- a/lib/clixon/clixon_json.h
+++ b/lib/clixon/clixon_json.h
@@ -28,7 +28,7 @@
*/
int json_parse_str(char *str, cxobj **xt);
-int xml2json_cbuf(cbuf *cb, cxobj *x, int level);
-int xml2json(FILE *f, cxobj *x, int level);
+int xml2json_cbuf(cbuf *cb, cxobj *x, int pretty);
+int xml2json(FILE *f, cxobj *x, int pretty);
#endif /* _CLIXON_JSON_H */
diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c
index 1f355745..2c99f622 100644
--- a/lib/src/clixon_json.c
+++ b/lib/src/clixon_json.c
@@ -22,6 +22,72 @@
*
* JSON support functions.
+curl -G http://localhost/api/data/sender/userid=a4315f60-e890-4f8f-9a0b-eb53d4da2d3a
+
+[{
+ "sender": {
+ "name": "dk-ore",
+ "userid": "a4315f60-e890-4f8f-9a0b-eb53d4da2d3a",
+ "ipv4_daddr": "109.105.110.78",
+ "template": "nordunet",
+ "version": "0",
+ "description": "Nutanix ORE",
+ "start": "true",
+ "udp_dport": "43713",
+ "debug": "0",
+ "proto": "udp"
+ }
+
+is translated into this:
+[
+ {"sender":
+ ["name":"dk-ore",
+ "userid":"a4315f60-e890-4f8f-9a0b-eb53d4da2d3a",
+ "ipv4_daddr":"109.105.110.78",
+ "template":"nordunet",
+ "version":"0",
+ "description":"Nutanix ORE",
+ "start":"true",
+ "udp_dport":"43713",
+ "debug":"0",
+ "proto":"udp"}
+ ,
+ {"name":"dk-uni",
+
+
+-------------------------
+
+
+
+ hunerik
+
+
+ foo
+
+
+
+{ "t":
+ {
+ "sender": {
+ "name": "hunerik"
+ },
+ "sender": {
+ "name": "foo"
+ }
+ }
+}
+
+{
+ "t": {
+ "sender": [
+ { "name": "hunerik" },
+ { "name": "foo" }
+ ]
+ }
+}
+
+OK, still something wrong with grafana plots
+
*/
#include
@@ -47,6 +113,7 @@
#include "clixon_json.h"
#include "clixon_json_parse.h"
+#define INDENT 2 /* maybe we should set this programmatically? */
/*! x is element and has eactly one child which in turn has none
* Clone from clixon_xml_map.c
@@ -113,6 +180,7 @@ list_eval(cxobj *x)
return list;
}
+
/*!
* List only if adjacent,
* ie 123 -> {"a":[1,2],"b":3}
@@ -120,7 +188,9 @@ list_eval(cxobj *x)
*/
static int
xml2json1_cbuf(cbuf *cb,
- cxobj *x)
+ cxobj *x,
+ int level,
+ int pretty)
{
int retval = -1;
int i;
@@ -129,7 +199,6 @@ xml2json1_cbuf(cbuf *cb,
switch(xml_type(x)){
case CX_BODY:
- fprintf(stderr, "%s body %s\n", __FUNCTION__, xml_value(x));
if (xml_value(x))
cprintf(cb, "\"%s\"", xml_value(x));
else
@@ -137,33 +206,44 @@ xml2json1_cbuf(cbuf *cb,
break;
case CX_ELMNT:
list = list_eval(x);
- fprintf(stderr, "%s element %s\n", __FUNCTION__, xml_name(x));
switch (list){
case LIST_NO:
- cprintf(cb, "\"%s\":", xml_name(x));
+ cprintf(cb, "%*s\"%s\": ", pretty?(level*INDENT):0, "",xml_name(x));
if (!tleaf(x))
- cprintf(cb, "{");
+ cprintf(cb, "{%s", pretty?"\n":"");
break;
case LIST_FIRST:
- cprintf(cb, "\"%s\":[", xml_name(x));
+ cprintf(cb, "\"%*s\":[", pretty?(level*INDENT):0, xml_name(x));
+ if (!tleaf(x))
+ cprintf(cb, "{%s", pretty?"\n":"");
break;
default:
break;
}
for (i=0; i