json Module
The json module provides fast, safe JSON serialization and deserialization between JSON strings and native Djazair data types (Arrays, Maps, Booleans, Numbers, and Null).
Importing
djazair
use json
API Reference
| Function | Description |
|---|---|
json.decode(jsonString) | Parses a JSON string into corresponding Djazair types (Maps, Arrays, primitives). Alias: json.parse(). |
json.encode(value, indent?, sortKeys?) | Serializes a value into a JSON string with optional formatting indentation. Alias: json.stringify(). |
Example Usage
djazair
use json
# Decoding JSON string to native Map
let raw = `{"project": "Djazair", "stars": 1500, "stable": true}`
let data = json.decode(raw)
print(data["project"]) # => Djazair
print(data["stars"]) # => 1500
# Modifying and Encoding back with 2-space indentation
data["stars"] += 50
data["tags"] = ["scripting", "compiler", "c"]
let jsonOutput = json.encode(data, 2)
print(jsonOutput)