SKU // 118

JSON Values

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.

// The Six Kinds of Values

JSON type Examples Becomes in JavaScript
string"hello"a string
number42, 3.14, -7, 2e3a number
object{"a": 1}an object
array[1, 2]an array
booleantrue, falsea boolean
nullnullnull
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);
string number object true boolean null

// Strings

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.

// Numbers

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
007leading zeros are not allowed
0x1Fhex is not allowed
+5a leading plus is not allowed
5. or .5digits are required on both sides of the point
NaN, Infinitynot 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 true true false false false false false

// Booleans and null

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.

// Objects and Arrays Nest

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]);
Coding Sam 77

// What JSON Cannot Hold

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
undefinedUse null, or leave the key out
functionsCannot be sent. JSON is data, not behavior
Date objectsStore them as text, usually ISO format like "2026-10-02T14:30:00Z"
NaN, InfinityNot allowed. Store a string or null
BigIntNot allowed. Store it as a string
Map, SetConvert to an array or object first

// Dates Are Just Strings

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());
string 2026-10-02T14:30:00.000Z 2026
null versus missing
A key with the value 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.

// Quick Check

Which of these is NOT a legal JSON value?

  1. "text"
  2. [1, 2]
  3. undefined
  4. null
Show answer
C. undefined 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);
Show answer
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.

Show answer
Any three of: undefined, functions, Date objects, NaN or Infinity, BigInt, Map and Set.

// Try It

  1. Click Open Playground and run it. Which of the six JSON types does each key hold?
  2. Add a seventh key with an array of objects, then read a property from the second object
  3. Write JSON for your favorite book with a title, a page count, an array of genres, and a null rating
  4. Store today's date in JSON as text, parse it, and turn it back into a Date
// Video Walkthroughs
Last updated: Oct 11, 2026, 5:23 PM ET