Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JavaScript · Module

JSON

The global JSON namespace provides static methods for parsing JSON text and converting JavaScript values to JSON. It is not a constructor; use methods such as JSON.parse() and JSON.stringify().

How it works

The global JSON namespace provides static methods for converting between JavaScript values and JSON text. Use JSON.stringify() to serialize supported values and JSON.parse() to construct a value from valid JSON text; JSON is a namespace object, not a constructor.

Syntax

JSON.parse(text, reviver)
JSON.stringify(value, replacer, space)
JSON.isRawJSON(value)
JSON.rawJSON(rawJSON)

Returns

The JSON namespace object; its static methods return method-specific parsed values, JSON strings, or raw JSON objects.

Key points

  • JSON groups static operations for parsing JSON text and producing JSON text.
  • Use JSON.stringify() to serialize a value, with optional filtering or replacement behavior.
  • Access operations directly through JSON.parse(), JSON.stringify(), and the other static members.

Common mistakes

  • Do not call JSON with new or treat it as a function; its members are static methods.
  • JSON cannot directly represent every JavaScript value, such as functions, regular expressions, or dates.

Example: Serialize and parse a value

const text = JSON.stringify({ answer: 42 });
const value = JSON.parse(text);
console.log(value.answer);

This serializes a JavaScript object to JSON text, then parses that text back into a JavaScript value.

When to use it

Network data serialization

Exchange structured data between a JavaScript application and a server.

State persistence

Persist application state in local storage or a file.

Input parsing

Convert external JSON text into usable JavaScript values.

Controlled serialization

Create readable or filtered JSON output for logs and APIs.

  • JSON.parse()
  • JSON.stringify()
  • JSON.isRawJSON()
  • JSON.rawJSON()

Source: JSON - JavaScript | MDN Web Docs. Checked 2026-10-15.