A number is used to store numeric values, such as age, price, temperature, or distance.
Unlike strings, numbers are not written inside quotation marks.
Here are some examples of valid numbers:
{
"students": 35,
"price": 49.99,
"temperature": -8.5,
"discount": 0.15,
"distanceToMoon": 3.84e8
}
In this example:
35 is a whole number.49.99 is a decimal number.-8.5 is a negative number.0.15 is a decimal smaller than 1.3.84e8 is scientific notation, which means 3.84 × 10⁸ (384,000,000).Numbers should be written without double quotes.
✅ Correct
{
"score": 92
}
❌ Wrong
{
"score": "92"
}
Why is it wrong? "92" is treated as text (a string), not a number.
JSON numbers use only the digits 0 to 9.
✅ Correct
{
"year": 2026
}
❌ Wrong
{
"value": 0x20
}
Why is it wrong? 0x20 is a hexadecimal number. JSON does not allow hexadecimal numbers.
A number should not have unnecessary zeros at the beginning.
✅ Correct
{
"day": 7
}
❌ Wrong
{
"day": 007
}
Why is it wrong? Leading zeros are not allowed in JSON numbers.
Use a decimal point (.) when a number has a fractional part.
✅ Correct
{
"weight": 65.8
}
❌ Wrong
{
"weight": 65,8
}
Why is it wrong? JSON uses a period (.) as the decimal separator, not a comma.
Very large or very small numbers can be written using e or E.
✅ Correct
{
"stars": 2.5e9
}
This means: 2.5 × 10⁹ = 2,500,000,000
Another valid example:
{
"tinyValue": 4.2E-3
}
This means: 4.2 × 10⁻³ = 0.0042
JSON does not support the special values NaN or Infinity.
✅ Correct
{
"result": null
}
❌ Wrong
{
"result": NaN
}
❌ Wrong
{
"result": Infinity
}
Why is it wrong? NaN and Infinity are allowed in JavaScript, but they are not valid JSON values.
| Number Type | Example |
|---|---|
| Whole Number | 45 |
| Decimal Number | 19.75 |
| Negative Number | -12 |
| Decimal Less Than 1 | 0.8 |
| Scientific Notation | 5.6e7 |