common: add simple json parse wrapper for the complete cases.

We're going to change the API on the more complete JSON parser, so
make and use a simple API for the easy cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2020-08-20 09:46:55 +09:30
parent 40f17d994c
commit 80b2e1e298
6 changed files with 31 additions and 25 deletions

View File

@@ -144,19 +144,18 @@ static void test_json_tok_size(void)
/* This should *not* parse! (used to give toks[0]->size == 2!) */
buf = "{ 'satoshi', '546' }";
toks = json_parse_input(tmpctx, buf, strlen(buf), &ok);
assert(!ok);
toks = json_parse_simple(tmpctx, buf, strlen(buf));
assert(!toks);
}
static void test_json_delve(void)
{
const jsmntok_t *toks, *t;
char *buf;
bool ok;
buf = "{\"1\":\"one\", \"2\":\"two\", \"3\":[\"three\", {\"deeper\": 17}]}";
toks = json_parse_input(tmpctx, buf, strlen(buf), &ok);
assert(ok);
toks = json_parse_simple(tmpctx, buf, strlen(buf));
assert(toks);
assert(toks->size == 3);
t = json_delve(buf, toks, ".1");
@@ -227,8 +226,8 @@ static void test_json_delve(void)
" }\n"
"}\n"
"\n";
toks = json_parse_input(tmpctx, buf, strlen(buf), &ok);
assert(ok);
toks = json_parse_simple(tmpctx, buf, strlen(buf));
assert(toks);
assert(toks->size == 4);
t = json_delve(buf, toks, ".rpcfile");