Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-01-07 17:46:31 +0300
committerJo-Philipp Wich <jo@mein.io>2018-01-07 18:02:02 +0300
commit1dafcd7813f147811a6bbdb00eec603fe732aac1 (patch)
tree07630d0a33336889cecea4e7112b15cd4bbfa740
parent6abafba0c4d38d109c7563d9c09b51d627002cb6 (diff)
jshn: properly support JSON "null" type
Instead of abort parsing, properly deal with "null" values by implementing support for reading and formatting such values. Signed-off-by: Jo-Philipp Wich <jo@mein.io> (cherry picked from commit 1c08e80313fd487112c48346889cc57badeef751)
-rw-r--r--jshn.c11
-rw-r--r--sh/jshn.sh6
2 files changed, 14 insertions, 3 deletions
diff --git a/jshn.c b/jshn.c
index 79136dd..3188af5 100644
--- a/jshn.c
+++ b/jshn.c
@@ -105,9 +105,6 @@ static int add_json_element(const char *key, json_object *obj)
{
char *type;
- if (!obj)
- return -1;
-
switch (json_object_get_type(obj)) {
case json_type_object:
type = "object";
@@ -127,6 +124,9 @@ static int add_json_element(const char *key, json_object *obj)
case json_type_double:
type = "double";
break;
+ case json_type_null:
+ type = "null";
+ break;
default:
return -1;
}
@@ -159,6 +159,9 @@ static int add_json_element(const char *key, json_object *obj)
case json_type_double:
fprintf(stdout, "' %lf;\n", json_object_get_double(obj));
break;
+ case json_type_null:
+ fprintf(stdout, "';\n");
+ break;
default:
return -1;
}
@@ -240,6 +243,8 @@ static void jshn_add_object_var(json_object *obj, bool array, const char *prefix
new = json_object_new_double(strtod(var, NULL));
} else if (!strcmp(type, "boolean")) {
new = json_object_new_boolean(!!atoi(var));
+ } else if (!strcmp(type, "null")) {
+ new = NULL;
} else {
return;
}
diff --git a/sh/jshn.sh b/sh/jshn.sh
index bf76edb..1090814 100644
--- a/sh/jshn.sh
+++ b/sh/jshn.sh
@@ -168,6 +168,12 @@ json_add_double() {
_json_add_generic double "$1" "$2" "$cur"
}
+json_add_null() {
+ local cur
+ _json_get_var cur JSON_CUR
+ _json_add_generic null "$1" "" "$cur"
+}
+
# functions read access to json variables
json_load() {