- printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n\n",
- XML_ENCODING);
- printf("<%s>\n", ROOT_TAG);
- printf(" <%s>\n", META_TAG);
- printf(" <%s>%lu</%s>\n", META_START_TAG,
- (unsigned long) start + step, META_START_TAG);
- printf(" <%s>%lu</%s>\n", META_STEP_TAG, step, META_STEP_TAG);
- printf(" <%s>%lu</%s>\n", META_END_TAG, (unsigned long) end,
- META_END_TAG);
- printf(" <%s>%lu</%s>\n", META_ROWS_TAG, row_cnt,
- META_ROWS_TAG);
- printf(" <%s>%lu</%s>\n", META_COLS_TAG, col_cnt,
- META_COLS_TAG);
- printf(" <%s>\n", LEGEND_TAG);
+ if (json == 0){
+ printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n\n",
+ XML_ENCODING);
+ printf("<%s>\n", ROOT_TAG);
+ printf(" <%s>\n", META_TAG);
+ }
+ else {
+ printf("{ about: 'RRDtool xport JSON output',\n meta: {\n");
+ }
+
+
+#define pXJV(indent,fmt,tag,value) \
+ if (json) { \
+ printf(indent "%s: " fmt ",\n",tag,value); \
+ } else { \
+ printf(indent "<%s>" fmt "</%s>\n",tag,value,tag); \
+ }
+
+ pXJV(" ","%lld",META_START_TAG,(long long int) start + step);
+ pXJV(" ","%lu", META_STEP_TAG, step);
+ pXJV(" ","%lld",META_END_TAG,(long long int) start + step);
+ if (! json){
+ pXJV(" ","%lu", META_ROWS_TAG, row_cnt);
+ pXJV(" ","%lu", META_COLS_TAG, col_cnt);
+ }
+
+ if (json){
+ printf(" %s: [\n", LEGEND_TAG);
+ }
+ else {
+ printf(" <%s>\n", LEGEND_TAG);
+ }