File I/O¶
Load, save, create and reload JSON files. Relative paths resolve against the
server's scriptfiles/ directory — so "data/players.json" means
scriptfiles/data/players.json. Absolute paths and ./, ../ or
scriptfiles/... prefixes are used as-is. Parent directories are created
automatically on save/create.
json_open_file¶
Reads and parses the file into a new handle. Returns 1 on success;
0 on empty path (E010), read error (E011) or invalid JSON (E012).
new doc;
if (json_open_file("data/players.json", doc))
{
new name[24];
json_get_string(doc, "name", name);
json_free(doc);
}
json_save_file¶
Serializes the handle (pretty-printed) and writes it to path. Returns 1 on
success; 0 on empty path (E013), missing handle (E002), serialization
failure (E014), directory creation failure (E015) or write failure (E016).
json_create_file¶
Ensures the file exists, writing an empty {} if it does not. If the file already
exists it is left untouched. Returns 1 on success; 0 on empty path (E017),
directory creation failure (E018) or write failure (E019).
json_reload_file¶
Re-reads path from disk into the same handle, discarding in-memory changes.
Useful after an external edit. Returns 1 on success; 0 on empty path (E020),
missing handle (E002), read error (E021) or invalid JSON (E022).