big integer not support
changnet opened this issue · 1 comments
changnet commented
Sometimes need to use big integer in json(unique IDs generate by diffrent process, a 64bit long long int)。But parson only support double,is there any plan to add big int support?
void test12(void) {
char *str;
double parse_big;
JSON_Object *parse_obj;
JSON_Value *parse_val;
JSON_Value *val = json_value_init_object();
JSON_Object *obj = json_value_get_object(val);
// json_object_set_bigint ?
json_object_set_number(obj, "bigint", 9223372036854775807);
str = json_serialize_to_string(val);
printf("result: %s\n", str);
parse_val = json_parse_string(str);
parse_obj = json_value_get_object(parse_val);
parse_big = json_object_get_number(parse_obj, "bigint");
printf("parse %f\n",parse_big);
json_value_free(parse_val);
json_free_serialized_string(str);
json_value_free(val);
}
output
result: {"bigint":9.2233720368547758e+18} #expect {“bigint":9223372036854775807}
parse 9223372036854775808.000000 #expect 9223372036854775807
kgabis commented
No, only doubles will be supported. Passing around big integer values as numbers in json is quite risky because you don't have any guarantee that parsers will support them. I suggest serialising them to strings first.