saveJson(filePath, data, [ensurePath]) Last updated: 17. Oct 2026

API only function

Saves data as a JSON file to Docly with specified content stringified to JSON format.
This function is ideal for storing structured data in a standardized format.
For more advanced document saving with custom schemas, consider using the saveFile function.

Saving into #/API/ is not allowed (error 999), nor names ending in .hash or .js. The call runs as the user who published the site, not as the visitor. Check the visitor's own rights with allowModify before you change anything on their behalf.

See also: Path traversal

Parameters

Name Type Description
filePath string

The absolute path where the JSON file will be saved in Docly. Ensure the path is correct and includes the desired filename with a .json extension.

data object

The data to be stored, which will be automatically converted to JSON on the server side.
If a string is provided instead of an object, it will be saved directly as text without JSON conversion.

ensurePath (optional) bool

If true the folder path will be created if it is missing.
Default is false.

Returns

An object with timestamp, id, guid, filename and warning — the same as saveFile. warning is null unless something looks wrong, such as a double extension.

Example

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
// This will save a file to Docly in JSON format and ensure the path exists (if not it will create the folder "Test Files")
let data = { "Property" : "Test value" };
docly.saveJson("Test files/Test.json", data, true);