Text format
JSON is a string until it is parsed.
JSON is a text format for structured data. It is how JavaScript objects often travel through APIs, files and storage.
const json = '{"title":"Dashboard","active":true}';
const data = JSON.parse(json);
console.log(data.title);
JSON & Structured Data
JSON stands for JavaScript Object Notation, but it is a language-independent data format. APIs, configuration files and browser storage often use it.
JSON looks like JavaScript object syntax, but it is stricter. Property names must use double quotes, strings use double quotes, comments are not allowed and trailing commas are invalid.
Treat JSON as untrusted input when it comes from outside your code. Parse it, validate the shape and then use it as structured data.
JSON is a string until it is parsed.
Double quoted keys and strings are required.
JSON cannot store functions, undefined or comments.
JSON is the default shape for many web APIs.
Examples
const data = JSON.parse(json);
if (typeof data.title !== "string") {
throw new Error("Invalid record title");
}
const data = JSON.parse(json); output.textContent = data.title.toUpperCase(); // This fails when title is missing or not a string.
Code patterns
These patterns focus on the data boundaries you will use constantly: JSON, URLs, forms, files, fetch objects and binary buffers.
Keys and string values use double quotes.
const json = '{"title":"Dashboard","active":true}';
const data = JSON.parse(json);
JSON can represent ordered lists too.
const json = '["html","css","javascript"]'; const topics = JSON.parse(json);
Use strings, numbers, booleans, null, arrays and objects.
const data = {
title: "Dashboard",
count: 3,
active: true,
owner: null
};
Parsing only checks syntax, not whether the shape is useful.
const data = JSON.parse(json);
if (typeof data.title !== "string") {
throw new Error("Missing title");
}
Rules that matter
Structured data becomes reliable when every boundary is explicit: text to object, form to values, URL to parameters, response to JSON and bytes to meaning.
Parse it before using it as data.
No comments, functions, undefined or trailing commas.
Syntax validity does not prove the data shape is correct.
JSON supports null, but not undefined.
Dates, Maps and Sets need custom conversion.
Invalid JSON throws a SyntaxError.
Production thinking
JSON is the bridge between JavaScript and external systems. If that bridge is weak, data bugs spread quickly.
Data-driven UI should validate labels and states before rendering them to users.
Production code should parse JSON at boundaries and validate required fields before business logic uses them.
Structured data and page metadata must be valid JSON when embedded for crawlers.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Structured data is safe only when you know where it came from, what shape it has and what conversion happened before use.