Skip to content

Commit

Permalink
Merge pull request #10 from lcsmuller/v1.0.0-rewrite
Browse files Browse the repository at this point in the history
Rewrite API and settle on a final design
  • Loading branch information
lcsmuller authored Apr 27, 2022
2 parents a44653a + 0a915eb commit 0740ec6
Show file tree
Hide file tree
Showing 5 changed files with 351 additions and 318 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ jsmnf_pair *f;
// assume the JSON : { "foo": { "bar": [ true, null, null ] } }
if ((f = jsmnf_find(pairs, json, "foo", strlen("foo")))) {
// Found: { "bar" : [ true, null, null ] }
printf("Found: %.*s\n", f->value.end - f->value.start, json + f->value.start);
printf("Found: %.*s\n", f->v.len, json + f->v.pos);
if ((f = jsmnf_find(f, json, "bar", 3))) {
// Found: [ true, null, null ]
printf("Found: %.*s\n", f->value.end - f->value.start, json + f->value.start);
printf("Found: %.*s\n", f->v.len, json + f->v.pos);
if ((f = jsmn_find(f, json, "0", 1))) {
// Found: true
printf("Found: %.*s\n", f->value.end - f->value.start, json + f->value.start);
printf("Found: %.*s\n", f->v.len, json + f->v.pos);
}
}
}
Expand All @@ -72,10 +72,10 @@ jsmnf_pair *f;
// assume the JSON : [ null, [ true, null, null ] ]
f = &pairs->buckets[1];
// Found: [ true, null, null ]
printf("Found: %.*s\n", f->value.end - f->value.start, json + f->value.start);
printf("Found: %.*s\n", f->v.len, json + f->v.pos);
f = &f->buckets[0];
// Found: true
printf("Found: %.*s\n", f->value.end - f->value.start, json + f->value.start);
printf("Found: %.*s\n", f->v.len, json + f->v.pos);
```
`find path (key search for objects and arrays)`
Expand All @@ -86,7 +86,7 @@ jsmnf_pair *f;
// assume the JSON : [ 1, 2, [ 1, [ { "b":true } ] ] ]
if ((f = jsmnf_find_path(pairs, path, sizeof(path) / sizeof *path))) {
// Found: true
printf("Found: %.*s\n", f->value.end - f->value.start, json + f->value.start);
printf("Found: %.*s\n", f->v.len, json + f->v.pos);
}
```

Expand Down
Loading

0 comments on commit 0740ec6

Please sign in to comment.