diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-01-07 17:46:31 +0300 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-01-07 17:52:24 +0300 |
commit | 1c08e80313fd487112c48346889cc57badeef751 (patch) | |
tree | 7b691781d2f00e0d94d49b9a4bca66a66d096a0a /jshn.c | |
parent | 729f47fd5279f902986457682f8f166c324eafb5 (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>
Diffstat (limited to 'jshn.c')
-rw-r--r-- | jshn.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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; } |