logJson(filePath, data) Last updated: 13. May 2026

API only function

Creates a new JSON array file or adds a new item to the existing array in the file. This function works as a log, maintaining an array of events with automatic timestamping. If the log file path ends with '/', the current date (yyyyMMdd) will be automatically appended as the filename. The log automatically limits entries to prevent excessive file size.

See also: Path traversal

Parameters

Name Type Description
filePath string

The absolute path where the JSON log file will be saved or updated. Can be a complete file path with .json extension, or a directory path ending with '/' (in which case the current date in yyyyMMdd format will be used as the filename).

data object

The event data to be logged. This object will be wrapped in a log entry with an automatic timestamp (Time property) and stored in an Event property. The entry is appended to the existing array, or creates a new array if the file doesn't exist.

Returns

Returns a reference to the updated log file, including a unique GUID for the file, allowing for easy identification and retrieval.

Example

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
// Add a new event to a specific JSON log file
let newEvent = { "action": "User login", "userId": 12345 };
docly.logJson("Logs/UserActions.json", newEvent);

// Use automatic date-based filename (creates or appends to Logs/20240115.json)
let errorEvent = { "error": "Connection timeout", "severity": "high" };
docly.logJson("Logs/", errorEvent);