logJson(filePath, data)
Appends an entry to a JSON log file — a file holding a JSON array — and creates the file if it does not exist. If the path ends with '/', the current date (yyyyMMdd) is used as the file name.
Each entry is stored as { Time, Event }. When the file holds more than 10,000 entries, the oldest are dropped. Missing folders are created. If the file exists but does not hold a JSON array, its content is replaced by a new log.
Parameters
filePathstringrequiredThe 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).
dataobjectrequiredThe 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
The same object as saveJson: timestamp, id, guid, filename and warning.
Example
// 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);