Skip to content

Instantly share code, notes, and snippets.

@ktosiu
Created November 22, 2015 23:40
Show Gist options
  • Save ktosiu/48a8e063d84dca7d5a38 to your computer and use it in GitHub Desktop.
Save ktosiu/48a8e063d84dca7d5a38 to your computer and use it in GitHub Desktop.
jasson json_path test for branch json_path from https://github.com/rogerz/jansson.git
#include <jansson.h>
#include <string.h>
main()
{
json_t *json;
char *result;
// { "top": { "v1" : 1, "v2" : "mama", "a1" : [ 2, { "s1" : "hello" } ] } }
json = json_pack("{s:{s:i,s:s,s:[i,{s:s}]}}", "top", "v1", 1, "v2","mama","a1", 2, "s1", "hello");
result = json_dumps(json,0);
printf("%s\n",result);
free(result);
json = json_path_get(json, "$");
printf("v1: %d\n", json_integer_value(json_path_get(json , "$.top.v1")));
printf("v2: %s\n", json_string_value(json_path_get(json , "$.top.v2")));
printf("a1[0]: %d\n", json_integer_value(json_path_get(json , "$.top.a1[0]")));
printf("a1[1].s1: %s\n", json_string_value(json_path_get(json , "$.top.a1[1].s1")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment