From 39e81139f08d282feb6385c7f2f5693ae0d8c57e Mon Sep 17 00:00:00 2001 From: LDA Date: Fri, 25 Oct 2024 18:45:54 +0200 Subject: [PATCH] [ADD] Add JsonValueDecode to decode a simple value --- include/Cytoplasm/Json.h | 6 ++++++ src/Json.c | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/Cytoplasm/Json.h b/include/Cytoplasm/Json.h index 261aced..b2a6e23 100644 --- a/include/Cytoplasm/Json.h +++ b/include/Cytoplasm/Json.h @@ -297,6 +297,12 @@ extern size_t JsonEncode(HashMap *, Stream *, int); */ extern HashMap * JsonDecode(Stream *); +/** + * Decodes a JSON value from thr current input strram and parse it + * into a JsonValue. + */ +extern JsonValue * JsonValueDecode(Stream *); + /** * A convenience function that allows the caller to retrieve and * arbitrarily deep keys within a JSON object. It takes a root JSON diff --git a/src/Json.c b/src/Json.c index 872c266..df33703 100644 --- a/src/Json.c +++ b/src/Json.c @@ -1348,6 +1348,25 @@ JsonDecode(Stream * stream) return result; } +JsonValue * +JsonValueDecode(Stream *stream) +{ + JsonValue *result; + JsonParserState state; + + state.stream = stream; + state.token = NULL; + + JsonTokenSeek(&state); + result = JsonDecodeValue(&state); + + if (state.token) + { + Free(state.token); + } + + return result; +} JsonValue * JsonGet(HashMap * json, size_t nArgs,...) -- 2.45.2