From 2b1cba0b5382eb74d7f431a1e2431b0a1f66e5a0 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 17 Nov 2017 13:52:45 -0800 Subject: [PATCH] Warn during json-tool extraction if the extracted field isn't found --- jsontool.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jsontool.cpp b/jsontool.cpp index 77fa496..beaaa49 100644 --- a/jsontool.cpp +++ b/jsontool.cpp @@ -138,9 +138,11 @@ std::string sort_quote(const char *s) { void out(std::string const &s, int type, json_object *properties) { if (extract != NULL) { std::string extracted = sort_quote("null"); + bool found = false; json_object *o = json_hash_get(properties, extract); if (o != NULL) { + found = true; if (o->type == JSON_STRING || o->type == JSON_NUMBER) { extracted = sort_quote(o->string); } else { @@ -153,6 +155,14 @@ void out(std::string const &s, int type, json_object *properties) { } } + if (!found) { + static bool warned = false; + if (!warned) { + fprintf(stderr, "Warning: extract key \"%s\" not found in JSON\n", extract); + warned = true; + } + } + printf("{\"%s\":%s}\n", extracted.c_str(), s.c_str()); return; }