From 9d74bab6ae0e1381d2acdec90680269a90a244eb Mon Sep 17 00:00:00 2001 From: Meutel Date: Thu, 29 Dec 2016 23:33:42 +0100 Subject: [PATCH] Improve JSON output --- main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 6559a8b..1f653d7 100644 --- a/main.c +++ b/main.c @@ -105,15 +105,21 @@ sendbooks(struct kreq *r) kjson_open(&req, r); kjson_obj_open(&req); if (NULL == b) { - kjson_putstringp(&req, "data", "error"); + kjson_objp_open(&req, "error"); + kjson_putstringp(&req, "msg", "Unknown book"); + kjson_obj_close(&req); } else { + kjson_objp_open(&req, "book"); kjson_putstringp(&req, "data", "books"); kjson_putintp(&req, "id", b->id); kjson_putstringp(&req, "title", b->title); + kjson_obj_close(&req); } +#ifdef __DEBUG__ kjson_putstringp(&req, "_path", r->path); kjson_putstringp(&req, "_pname", r->pname); kjson_putstringp(&req, "_pagename", r->pagename); +#endif kjson_obj_close(&req); kjson_close(&req); }