jshn: read and write 64-bit integers
This allows for reading in and writing out bigger JSON Numbers. Following test script (that fails to print correct values _without_ this commit) verifies the functionality (tested on x86-64 as well as on ar71xx): ---snip--- # assumes you built jshn and sourced jshn.sh echo testing reading-in JSON SHELL_BIGNUM=12147483647 json_init json_load "{ \"bignum\": $SHELL_BIGNUM }" json_get_var BIGNUM bignum echo jshn bignum: $BIGNUM echo shll bignum: $SHELL_BIGNUM echo testing writing-out JSON json_init json_add_int bigint $SHELL_BIGNUM json_dump --snap--- Signed-off-by: Christian Beier <dontmind@freeshell.org>
This commit is contained in:
parent
632688e8d6
commit
729f47fd52
1 changed files with 2 additions and 2 deletions
4
jshn.c
4
jshn.c
|
@ -154,7 +154,7 @@ static int add_json_element(const char *key, json_object *obj)
|
||||||
fprintf(stdout, "' %d;\n", json_object_get_boolean(obj));
|
fprintf(stdout, "' %d;\n", json_object_get_boolean(obj));
|
||||||
break;
|
break;
|
||||||
case json_type_int:
|
case json_type_int:
|
||||||
fprintf(stdout, "' %d;\n", json_object_get_int(obj));
|
fprintf(stdout, "' %jd;\n", json_object_get_int64(obj));
|
||||||
break;
|
break;
|
||||||
case json_type_double:
|
case json_type_double:
|
||||||
fprintf(stdout, "' %lf;\n", json_object_get_double(obj));
|
fprintf(stdout, "' %lf;\n", json_object_get_double(obj));
|
||||||
|
@ -235,7 +235,7 @@ static void jshn_add_object_var(json_object *obj, bool array, const char *prefix
|
||||||
} else if (!strcmp(type, "string")) {
|
} else if (!strcmp(type, "string")) {
|
||||||
new = json_object_new_string(var);
|
new = json_object_new_string(var);
|
||||||
} else if (!strcmp(type, "int")) {
|
} else if (!strcmp(type, "int")) {
|
||||||
new = json_object_new_int(atoi(var));
|
new = json_object_new_int64(atoll(var));
|
||||||
} else if (!strcmp(type, "double")) {
|
} else if (!strcmp(type, "double")) {
|
||||||
new = json_object_new_double(strtod(var, NULL));
|
new = json_object_new_double(strtod(var, NULL));
|
||||||
} else if (!strcmp(type, "boolean")) {
|
} else if (!strcmp(type, "boolean")) {
|
||||||
|
|
Loading…
Reference in a new issue