config.h: make JSON output indentable (or not)

This commit is contained in:
Jan-Piet Mens 2015-09-02 20:03:41 +02:00
parent 9c33852a3e
commit 17aada0b3e
4 changed files with 16 additions and 9 deletions

View File

@ -27,3 +27,10 @@
*/
#define DEFAULT_HISTORY_HOURS 6
/*
* Indented JSON or not? Choose.
*/
#define JSON_INDENT " " /* indented */
// #define JSON_INDENT NULL /* not indented */

View File

@ -151,7 +151,7 @@ int gcache_json_put(struct gcache *gc, char *ghash, JsonNode *geo)
fprintf(stderr, "%s\n", mdb_strerror(rc));
if ((js = json_stringify(geo, NULL)) == NULL) {
fprintf(stderr, "%s\n", "CANIT stringify");
fprintf(stderr, "%s\n", "CAN'T stringify JSON during gache_json_put()");
return (1);
}

4
http.c
View File

@ -121,7 +121,7 @@ void push_geojson(struct mg_connection *conn)
if (geojson != NULL) {
js = json_stringify(geojson, " ");
js = json_stringify(geojson, JSON_INDENT);
if (js != NULL) {
static char buf[40];
mg_send_header(conn, "Content-type", "application/json");
@ -217,7 +217,7 @@ int ev_handler(struct mg_connection *conn, enum mg_event ev)
if ((json = lister(NULL, NULL, 0, 0, FALSE)) != NULL) {
char *js;
js = json_stringify(json, " ");
js = json_stringify(json, JSON_INDENT);
mg_printf_data(conn, js);
free(js);
}

12
ocat.c
View File

@ -299,7 +299,7 @@ int main(int argc, char **argv)
// }
// }
js = json_stringify(obj, " ");
js = json_stringify(obj, JSON_INDENT);
printf("%s\n", js);
free(js);
json_delete(obj);
@ -313,7 +313,7 @@ int main(int argc, char **argv)
if ((user_array = last_users()) != NULL) {
char *js;
if ((js = json_stringify(user_array, " ")) != NULL) {
if ((js = json_stringify(user_array, JSON_INDENT)) != NULL) {
printf("%s\n", js);
free(js);
}
@ -348,7 +348,7 @@ int main(int argc, char **argv)
exit(2);
}
if (otype == JSON) {
js = json_stringify(json, " ");
js = json_stringify(json, JSON_INDENT);
printf("%s\n", js);
free(js);
} else {
@ -417,7 +417,7 @@ int main(int argc, char **argv)
if (otype == JSON) {
char *js = json_stringify(obj, " ");
char *js = json_stringify(obj, JSON_INDENT);
if (js != NULL) {
printf("%s\n", js);
@ -433,7 +433,7 @@ int main(int argc, char **argv)
char *js;
if (geolinestring != NULL) {
js = json_stringify(geolinestring, NULL);
js = json_stringify(geolinestring, JSON_INDENT);
if (js != NULL) {
printf("%s\n", js);
free(js);
@ -446,7 +446,7 @@ int main(int argc, char **argv)
char *js;
if (geojson != NULL) {
js = json_stringify(geojson, " ");
js = json_stringify(geojson, JSON_INDENT);
if (js != NULL) {
printf("%s\n", js);
free(js);