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; }