Back to Tools

JSON.stringify() Online

Convert JavaScript objects to JSON strings instantly

Spaces: 2

Quick Examples

What is JSON.stringify()?

JSON.stringify() is a built-in JavaScript method that converts JavaScript objects, arrays, or values into JSON (JavaScript Object Notation) strings. This is essential for:

  • Sending data to web servers via HTTP requests
  • Storing data in localStorage or sessionStorage
  • Converting objects to strings for transmission
  • Creating JSON files from JavaScript data

Use our free JSON Beautifier to format the stringified output, or our JSON Fixer to repair any issues.

Syntax

JSON.stringify(value, replacer, space)

value

The JavaScript object, array, or value to convert to JSON string

replacer (optional)

A function or array to transform values before stringifying

space (optional)

Number of spaces for indentation (0-10) for pretty printing

Examples

Simple Object:

const obj = { name: "John", age: 30 };
JSON.stringify(obj);
// Output: '{"name":"John","age":30}'

With Pretty Print (spaces = 2):

JSON.stringify(obj, null, 2);
// Output:
// {
//   "name": "John",
//   "age": 30
// }

More JSON Tools

Need to parse JSON strings? Use our JSON Beautifier or JSON Fixer for validation and repair.