diff --git a/common/json_parse_simple.c b/common/json_parse_simple.c index cf781611e..f7ce964ca 100644 --- a/common/json_parse_simple.c +++ b/common/json_parse_simple.c @@ -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 -----------------------------------------------------------------------------*/ diff --git a/common/json_parse_simple.h b/common/json_parse_simple.h index d0670b013..4188a4eb4 100644 --- a/common/json_parse_simple.h +++ b/common/json_parse_simple.h @@ -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);