JSONFile
Base class: Object
Represents a lazily loaded JSON document with explicit persistence.
value() returns detached data; set_value() and clear() change memory only. save() and save_as() persist changes. Selection uses RFC 6901 JSON Pointer, such as /samples/0; an empty pointer selects the root. Invalid pointers and missing locations throw. Typed reads accept native primitives or parsed strings.
Example
var file = JSONFile("results", "w")
file.set_value(["samples": [1.5, 2.5]]).save()
var values = file.value("/samples", as_list | as_real)
Constructors
JSONFile(const string path) -> JSONFile
Prepares a JSON document in append/update mode; missing files start with null.
Parameters
- path: Relative data-service path; .json is added when no extension exists.
JSONFile(const string path, const string mode) -> JSONFile
Prepares a JSON document. Modes are r, r+, w, w-/x, and a (default), without regard to case. Create modes start fresh and reload is available only in r/r+/a.
Parameters
- path: Relative data-service path.
- mode: File mode; an empty string uses a.
JSONFile(const string path, const string mode, const Map options) -> JSONFile
Prepares a JSON document with immutable serialization options.
Parameters
- path: Relative data-service path.
- mode: File mode.
- options: Boolean pretty (default true): two-space indentation or compact JSON; no final newline.
Members
| Name | Description |
|---|---|
| clear | Resets the in-memory value to null without touching the file. |
| path | Returns the resolved JSON path. |
| reload | Discards changes and reloads in r/r+/a modes; failures preserve the previous value. |
| save | Atomically persists the current value to the local file. |
| save_as | Atomically saves to a new local path and makes it current after success. |
| set_value | Validates and replaces the entire in-memory value without reading old contents. Registered modules also support nested numeric containers. Mutations require a writable mode. |
| value | Returns a JSON Pointer-selected value as an array or matrix with logical rows (flat inputs are row vectors). Complex elements use strings. |