Skip to content

Instantly share code, notes, and snippets.

@deltheil
Created September 27, 2012 12:51
Show Gist options
  • Save deltheil/3793838 to your computer and use it in GitHub Desktop.
Save deltheil/3793838 to your computer and use it in GitHub Desktop.
Checking parsing error with json-parser (https://github.com/udp/json-parser/)
#include <stdio.h>
#include <string.h>
#include <json-parser/json.h>
int main(int argc, char *argv[]) {
char *str[] = { "{\"foo\": \"bar\"}" /* ok */, "{\"foo\": \"bar}" /* ko */ };
for (int i = 0; i < 2; i++) {
json_settings settings;
memset(&settings, 0, sizeof(json_settings));
char err[256];
json_value *val = json_parse_ex(&settings, str[i], err);
if (val == 0) {
/* Parsing error */
fprintf(stderr, "[KO]: %s\n", err);
}
else {
fprintf(stdout, "[OK]\n");
json_value_free(val);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment