diff --git a/README.md b/README.md
index ab59a291..4fb40bc8 100644
--- a/README.md
+++ b/README.md
@@ -99,7 +99,9 @@ have no additional data.
Strings have type JSON_STRING, with null-terminated UTF-8 text
in string and length in length.
-Numbers have type JSON_NUMBER, with value in number.
+Numbers have type JSON_NUMBER, with value in number,
+and also preserve the original representation of the number
+in string and length in length.
Arrays have type JSON_ARRAY. There are length elements in the array,
and the elements are in array.
diff --git a/jsonpull.c b/jsonpull.c
index 16f67688..5977f8fb 100644
--- a/jsonpull.c
+++ b/jsonpull.c
@@ -414,8 +414,11 @@ again:
json_object *n = add_object(j, JSON_NUMBER);
if (n != NULL) {
n->number = atof(val.buf);
+ n->string = val.buf;
+ n->length = val.n;
+ } else {
+ string_free(&val);
}
- string_free(&val);
return n;
}
@@ -542,7 +545,7 @@ void json_free(json_object *o) {
free(k);
free(v);
- } else if (o->type == JSON_STRING) {
+ } else if (o->type == JSON_STRING || o->type == JSON_NUMBER) {
free(o->string);
}