JSON Introduction

Beginner
6 min read
Updated: Oct 2026
Data format

What Is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based format for structured data. It uses key–value pairs and arrays that both humans and programs can read—the default format for most REST APIs.

Remember
JSON is text, not a live object:
  Objects  →  { "key": "value" }
  Arrays   →  [1, 2, 3]

Rules: double-quoted keys & strings · no comments · no trailing commas

JS: JSON.parse(text)  ↔  JSON.stringify(obj)

Despite the name, JSON is language-independent. Python, Java, PHP, Go, and many others all have parsers. It looks like a JavaScript object literal, but with stricter rules.

Why Use JSON?

Apps need a shared way to exchange structured data. JSON is compact, readable, and supported almost everywhere.

NeedHow JSON helps
API responsesStandard payload for REST and many GraphQL clients
Config filesSettings for apps, build tools, and CI pipelines
Easy for humansReadable text you can inspect in DevTools
Easy for machinesFast to parse in every major language

How JSON Flows in a Web App

Typical path from server to your code:

StepWhat happens
1. SendServer returns a JSON text body (or you save a .json file)
2. ReceiveClient gets a string over HTTP
3. ParseJSON.parse() or response.json() builds objects in memory
4. UseYour code reads fields, updates the UI, or stringifies data to send back

Your First JSON Object

A simple user record, then parse it in JavaScript:

JSON
{
  "name": "John Doe",
  "age": 30,
  "city": "New York"
}
JavaScript
const jsonString = '{"name":"John Doe","age":30,"city":"New York"}';
const data = JSON.parse(jsonString);
console.log(data.name); // John Doe

const text = JSON.stringify(data);
console.log(text);

How It Works

1. Structure. Curly braces hold key–value pairs; keys and string values use double quotes.

2. Parse. JSON.parse turns the text into a live JavaScript object.

3. Stringify. JSON.stringify turns an object back into JSON text for storage or APIs.

Next, compare formats in JSON vs XML.

JSON vs XML

Both can carry structured data; JSON won most modern APIs:

JSONXML
Lightweight textHeavier with opening/closing tags
Maps cleanly to objects/arraysDocument tree with attributes
No comments in standard JSONSupports comments
Default for most REST APIsStill used in SOAP, RSS, and legacy systems

When to choose which

Prefer JSON when…Prefer XML when…
You build web or mobile APIsYou integrate with SOAP or older enterprise systems
You want less verbose payloadsYou need schemas and namespaces already in XML
Your client is JavaScript-heavyYour industry standard still requires XML

JSON Data Types

Only these value types are valid in JSON:

TypeExampleNotes
String"hello"Must use double quotes
Number42, 3.14Integer or decimal
Booleantrue, falseLowercase only
nullnullEmpty or missing value
Array[1, 2, 3]Ordered list of values
Object{"key": "value"}Collection of key–value pairs

Where Is JSON Used?

JSON shows up across modern software:

Use caseWhy JSON fits
Web & mobile APIsCompact responses browsers and apps already understand
Configurationpackage.json, app settings, CI configs
Document databasesMongoDB and similar stores JSON-like documents
Logging & analyticsStructured events that tools can index
MicroservicesShared message format between services
Data exportEasy interchange between apps and languages

Key Takeaways

  • JSON is a text data format—not executable JavaScript.
  • Rules: double quotes, no comments, no trailing commas.
  • JS helpers: parse reads JSON; stringify writes it.
  • Everywhere: APIs, configs, and document stores rely on it.

One line: JSON is the web’s shared data text—next, compare JSON vs XML.

Frequently Asked Questions

JSON (JavaScript Object Notation) is a lightweight, text-based format for structured data. It uses key-value pairs and arrays that both humans and programs can read easily. It is the most common format for REST APIs and configuration files.
They look similar, but JSON is a string format with strict rules—keys must be double-quoted, and functions and undefined values are not allowed. JavaScript objects live in memory; JSON is text you send over the network or save in a file.
Basic JavaScript helps because JSON syntax mirrors JS object literals. However, JSON is language-independent—Python, Java, PHP, and Go all have JSON parsers. Many beginners learn JSON while studying web APIs.
No. Standard JSON does not support comments. If you need annotated config files, use JSONC in editors that support it, or switch to YAML for human-edited configs with comments.
Use a JSON validator tool, browser DevTools, or an IDE with JSON linting. Common errors include trailing commas, single quotes instead of double quotes, and unquoted keys.
Study JSON vs XML, then syntax rules and data types. Practice JSON.parse and JSON.stringify in JavaScript, call REST APIs with fetch, and explore JSON Schema for validating API payloads.

Did you know?

JSON uses double-quoted keys and strings, objects in { }, and arrays in [ ]. In JavaScript, convert text to data with JSON.parse() and data to text with JSON.stringify().

Next: JSON vs XML

See how JSON compares to XML for APIs and documents.

JSON vs XML →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful