Improve JSON output

This commit is contained in:
Meutel 2016-12-29 23:33:42 +01:00
parent 8606c034e4
commit 9d74bab6ae

8
main.c
View File

@ -105,15 +105,21 @@ sendbooks(struct kreq *r)
kjson_open(&req, r); kjson_open(&req, r);
kjson_obj_open(&req); kjson_obj_open(&req);
if (NULL == b) { if (NULL == b) {
kjson_putstringp(&req, "data", "error"); kjson_objp_open(&req, "error");
kjson_putstringp(&req, "msg", "Unknown book");
kjson_obj_close(&req);
} else { } else {
kjson_objp_open(&req, "book");
kjson_putstringp(&req, "data", "books"); kjson_putstringp(&req, "data", "books");
kjson_putintp(&req, "id", b->id); kjson_putintp(&req, "id", b->id);
kjson_putstringp(&req, "title", b->title); kjson_putstringp(&req, "title", b->title);
kjson_obj_close(&req);
} }
#ifdef __DEBUG__
kjson_putstringp(&req, "_path", r->path); kjson_putstringp(&req, "_path", r->path);
kjson_putstringp(&req, "_pname", r->pname); kjson_putstringp(&req, "_pname", r->pname);
kjson_putstringp(&req, "_pagename", r->pagename); kjson_putstringp(&req, "_pagename", r->pagename);
#endif
kjson_obj_close(&req); kjson_obj_close(&req);
kjson_close(&req); kjson_close(&req);
} }