common: helper to get id field as a string.
We'll be doing this quite a bit, so provide common helper. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
5d25934865
commit
88354b79bd
|
@ -187,6 +187,15 @@ const jsmntok_t *json_get_arr(const jsmntok_t tok[], size_t index)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const char *json_get_id(const tal_t *ctx,
|
||||
const char *buffer, const jsmntok_t *obj)
|
||||
{
|
||||
const jsmntok_t *idtok = json_get_member(buffer, obj, "id");
|
||||
if (!idtok)
|
||||
return NULL;
|
||||
return json_strdup(ctx, buffer, idtok);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
JSMN Result Validation Starts
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -62,6 +62,10 @@ const jsmntok_t *json_get_member(const char *buffer, const jsmntok_t tok[],
|
|||
/* Get index'th array member. */
|
||||
const jsmntok_t *json_get_arr(const jsmntok_t tok[], size_t index);
|
||||
|
||||
/* Helper to get "id" field from object. */
|
||||
const char *json_get_id(const tal_t *ctx,
|
||||
const char *buffer, const jsmntok_t *obj);
|
||||
|
||||
/* Allocate a starter array of tokens for json_parse_input */
|
||||
jsmntok_t *toks_alloc(const tal_t *ctx);
|
||||
|
||||
|
|
Loading…
Reference in New Issue