+/*
+ * Returns true if the provided JSON could be parsed by yajl.
+ *
+ */
+bool json_validate(const char *buf, const size_t len) {
+ bool valid = true;
+ yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
+ /* Allowing comments allows for more user-friendly layout files. */
+ yajl_config(hand, yajl_allow_comments, true);
+ /* Allow multiple values, i.e. multiple nodes to attach */
+ yajl_config(hand, yajl_allow_multiple_values, true);
+
+ setlocale(LC_NUMERIC, "C");
+ if (yajl_parse(hand, (const unsigned char *)buf, len) != yajl_status_ok) {
+ unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
+ ELOG("JSON parsing error: %s\n", str);
+ yajl_free_error(hand, str);
+ valid = false;
+ }
+ setlocale(LC_NUMERIC, "");
+
+ yajl_complete_parse(hand);
+ yajl_free(hand);
+
+ return valid;
+}
+