From 8c527f393193a599ea42bb5b74433c609f544382 Mon Sep 17 00:00:00 2001 From: ZmnSCPxj Date: Fri, 26 Jan 2018 23:25:37 +0000 Subject: [PATCH] common/json: Implement json_add_snum for signed numbers. --- common/json.c | 5 +++++ common/json.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/common/json.c b/common/json.c index 371b43ae7..54290cfc8 100644 --- a/common/json.c +++ b/common/json.c @@ -457,6 +457,11 @@ void json_add_num(struct json_result *result, const char *fieldname, unsigned in json_start_member(result, fieldname); result_append_fmt(result, "%u", value); } +void json_add_snum(struct json_result *result, const char *fieldname, int value) +{ + json_start_member(result, fieldname); + result_append_fmt(result, "%d", value); +} void json_add_u64(struct json_result *result, const char *fieldname, uint64_t value) diff --git a/common/json.h b/common/json.h index b0501b6d0..8e3100824 100644 --- a/common/json.h +++ b/common/json.h @@ -89,6 +89,9 @@ void json_add_string(struct json_result *result, const char *fieldname, const ch void json_add_literal(struct json_result *result, const char *fieldname, const char *literal, int len); /* '"fieldname" : value' or 'value' if fieldname is NULL */ +void json_add_snum(struct json_result *result, const char *fieldname, + int value); +/* '"fieldname" : value' or 'value' if fieldname is NULL */ void json_add_num(struct json_result *result, const char *fieldname, unsigned int value); /* '"fieldname" : value' or 'value' if fieldname is NULL */