JSON allows exactly six kinds of values. Anything outside that list, such as undefined, a function, or a Date, has no JSON form. This lesson covers each of the six, what happens to them after parsing, and how to handle the things JSON cannot hold.
| JSON type | Examples | Becomes in JavaScript |
|---|---|---|
| string | "hello" | a string |
| number | 42, 3.14, -7, 2e3 | a number |
| object | {"a": 1} | an object |
| array | [1, 2] | an array |
| boolean | true, false | a boolean |
| null | null | null |
const text = '{"s":"hi","n":3.5,"o":{"x":1},"a":[1,2],"b":true,"z":null}';
const data = JSON.parse(text);
console.log(typeof data.s, typeof data.n, typeof data.o);
console.log(Array.isArray(data.a), typeof data.b, data.z);
Strings always use double quotes and can hold any text, including accented letters and emoji. Special characters need escapes (see JSON Syntax). A string is the only way to store text such as names, dates, and links.
JSON numbers are written the plain, decimal way. There is no separate integer type, just numbers. A few things that JavaScript accepts are not allowed:
| Text | Why it breaks |
|---|---|
007 | leading zeros are not allowed |
0x1F | hex is not allowed |
+5 | a leading plus is not allowed |
5. or .5 | digits are required on both sides of the point |
NaN, Infinity | not allowed |
function isValid(text) {
try { JSON.parse(text); return true; } catch (e) { return false; }
}
console.log(isValid("3.14"), isValid("-7"), isValid("2e3"));
console.log(isValid("007"), isValid("0x1F"), isValid("+5"));
console.log(isValid(".5"), isValid("NaN"));
true and false are the two booleans, always lowercase. null means "no value here on purpose". It is the closest JSON gets to undefined, which JSON cannot hold.
The value of any key, and every item in an array, can itself be an object or an array. There is no limit to how deep it goes:
{
"school": "CiTi",
"classes": [
{ "name": "Coding", "teacher": { "first": "Sam" }, "scores": [90, 85, 77] }
]
}
const data = JSON.parse(`{"school":"CiTi","classes":[{"name":"Coding","teacher":{"first":"Sam"},"scores":[90,85,77]}]}`);
console.log(data.classes[0].name);
console.log(data.classes[0].teacher.first);
console.log(data.classes[0].scores[2]);
These JavaScript values have no JSON form, and what happens to them depends on how you try to turn them into JSON (the Stringify lesson shows the details):
| Value | What to do |
|---|---|
undefined | Use null, or leave the key out |
| functions | Cannot be sent. JSON is data, not behavior |
Date objects | Store them as text, usually ISO format like "2026-10-02T14:30:00Z" |
NaN, Infinity | Not allowed. Store a string or null |
BigInt | Not allowed. Store it as a string |
Map, Set | Convert to an array or object first |
JSON has no date type. By convention a date is stored as an ISO text string, and you turn it back into a Date yourself after parsing:
const data = JSON.parse('{"joined":"2026-10-02T14:30:00.000Z"}');
console.log(typeof data.joined);
const when = new Date(data.joined);
console.log(when.toISOString());
console.log(when.getUTCFullYear());
null and a key that is simply absent look the same when you read them in JavaScript (data.x is null or undefined), but they mean different things. "phone": null says "we asked, and there is no phone". Leaving phone out says nothing at all. Pick one habit and keep it.
Which of these is NOT a legal JSON value?
"text"[1, 2]undefinednullundefined is not a JSON value. Use null or leave the key out.What does this log?
const d = JSON.parse('{"joined":"2026-10-02"}');
console.log(typeof d.joined);
string. JSON has no date type, so a date comes back as a string. Pass it to new Date(...) to get a real Date.Name three values that have no JSON form.
undefined, functions, Date objects, NaN or Infinity, BigInt, Map and Set.null rating