JSON is a text representation of same data, usually a structure like an array or an object but a primitive value like a string or a number can also be represented as JSON without problems.
Being a text, in the source code it is represented as a JavaScript string.
The line:
JSON.parse("60000528880e130012727947");
can be as well JSON.parse(x)
, where x
is a variable that contains the JSON.
The JSON in the example above is exactly this: 60000528880e130012727947
(there are no quotes around it, the quotes are the way a text is represented in the JavaScript source code). It is the text representation of a real number, 60,000,528,880 * 10^130,012,727,947
, to be more precise.
JavaScript uses double-precision 64-bit binary format IEEE 754 to represent the number. The largest value a Number can hold is about 1.8×10^308
which is very much for most practical purposes. However, it is a small value compared to the value you have represented as JSON.
Anyway, no matter how large it is, since the value stored as JSON is larger than the greatest value that can be represented using the 64-bit double-precision format, Infinity
is used instead.
Regarding the other example, 5ffc58ed1662010012d45b30
is not a valid representation of a number, therefore the JSON parser throws an error when it reaches the first f
character at index 1
.
All in all, JSON.parse()
works fine, your input is not always valid JSON.