ucoreJson
JSON parsing and serialization.
Strict Path Resolution: Unnarize enforces strict sandboxing. All file paths used in this library are resolved relative to the directory of the executing script, regardless of where the
unnarize command is run. Absolute paths are typically rebased or rejected to prevent sandbox escape.
Functions
| Function | Returns | Description |
|---|---|---|
parse(jsonString) |
Map/Array | Parse JSON string to value |
stringify(value) |
string | Serialize value to JSON string |
read(path) |
Map/Array | Read and parse JSON file |
write(path, value) |
bool | Write value to JSON file |
remove(path) |
bool | Delete a JSON file |
Basic Usage
parse / stringify
var jsonStr = '{"name":"Alice","age":30}';
var data = ucoreJson.parse(jsonStr);
print(data["name"]); // "Alice"
print(data["age"]); // 30
// Modify and serialize
data["age"] = 31;
var output = ucoreJson.stringify(data);
print(output); // {"name":"Alice","age":31}
File Operations
// Read JSON file
var config = ucoreJson.read("config.json");
print(config["version"]);
// Write JSON file
var settings = map();
settings["theme"] = "dark";
settings["language"] = "en";
ucoreJson.write("settings.json", settings);
Supported Types
- Objects → Unnarize Maps
- Arrays → Unnarize Arrays
- Strings → Unnarize Strings
- Numbers → Unnarize Numbers (int/float)
- Booleans → Unnarize Booleans
- null → Unnarize nil
Error Handling
Returns nil on parse errors.
var result = ucoreJson.parse("invalid json");
if (length(result) == 0) {
print("Parse error!");
}
remove(path)
Deletes a JSON file from disk. Returns true on success.
// Create a temporary file
var data = map();
data["temp"] = true;
ucoreJson.write("temp.json", data);
// Later, remove it
if (ucoreJson.remove("temp.json")) {
print("Temp file deleted");
}