From 976c6e5c835b01451c0d6ce5d4911085656c14f0 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 10 Sep 2020 13:52:33 +0930 Subject: [PATCH] json_add_tok: simplify, don't try to canonicalize. I'm not sure why we were turning strings into bools, etc. Signed-off-by: Rusty Russell --- common/json.c | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/common/json.c b/common/json.c index 4b84c0220..2c7fac185 100644 --- a/common/json.c +++ b/common/json.c @@ -830,44 +830,11 @@ void json_add_time(struct json_stream *result, const char *fieldname, void json_add_tok(struct json_stream *result, const char *fieldname, const jsmntok_t *tok, const char *buffer) { - int i = 0; - const jsmntok_t *t; + char *space; + assert(tok->type != JSMN_UNDEFINED); - switch (tok->type) { - case JSMN_PRIMITIVE: - if (json_tok_is_num(buffer, tok)) { - json_to_int(buffer, tok, &i); - json_add_num(result, fieldname, i); - } - return; - - case JSMN_STRING: - if (json_tok_streq(buffer, tok, "true")) - json_add_bool(result, fieldname, true); - else if (json_tok_streq(buffer, tok, "false")) - json_add_bool(result, fieldname, false); - else - json_add_string(result, fieldname, json_strdup(tmpctx, buffer, tok)); - return; - - case JSMN_ARRAY: - json_array_start(result, fieldname); - json_for_each_arr(i, t, tok) - json_add_tok(result, NULL, t, buffer); - json_array_end(result); - return; - - case JSMN_OBJECT: - json_object_start(result, fieldname); - json_for_each_obj(i, t, tok) - json_add_tok(result, json_strdup(tmpctx, buffer, t), t+1, buffer); - json_object_end(result); - return; - - case JSMN_UNDEFINED: - break; - } - abort(); + space = json_member_direct(result, fieldname, json_tok_full_len(tok)); + memcpy(space, json_tok_full(buffer, tok), json_tok_full_len(tok)); } void json_add_errcode(struct json_stream *result, const char *fieldname,