Docly Developers
Function Updated 23 Oct 2026

JSON.stringify(value, [replacer], [space])

Converts a JavaScript object or value to a JSON string. Numbers are written the JavaScript way (3, not 3.0), and object properties that are undefined are left out.

Parameters

valueobjectrequired

Object to convert to a JSON string.

replacerfunctionoptional

A function called as (key, value) for every value, whose return value is used instead — return undefined to leave a property out. Or an array of property names to keep. Any other value is ignored.

spacenumberoptional

Indentation: a number of spaces per level (at most 10), or a string of up to 10 characters repeated per level. Without it the JSON is compact.

Returns

The value as a JSON string — or undefined when the value is undefined or a function, as in standard JavaScript. In a template, #JSON.stringify(x)# therefore prints nothing when x is undefined.

replacer and space work as in standard JavaScript: JSON.stringify(obj, null, 2) indents with two spaces per level, and JSON.stringify(obj, ['id', 'name']) keeps only those properties.

Dates are written the way toISOString() writes them — UTC with milliseconds, for example "2026-01-31T11:00:00.000Z". The same format is used when values are saved with saveJson/saveFile and in API responses.

A function inside the value throws an error (standard JavaScript leaves it out), and that includes a toJSON method on your own object. Pass a replacer — for example JSON.stringify(obj, (key, value) => value) — and functions are left out as in standard JavaScript; toJSON on your own objects is not called.

Example

Mixed HTML (or any text file) with inline JavaScript between hash signs.
#write(JSON.stringify({"name":12}))#