جسون
Translation status: العربية reader-locale proof. Term names and code fences follow the ar pack; supporting prose may still be English.
Syntax:
Category#
type
Related#
None.
Examples#
radix/corpus/json/json.fab (canonical · type)#
# =============================================================================
# جسون — JSON serialization and deserialization
# =============================================================================
#
# What this teaches:
# • JSON type conversions using `↦` — converting between `جسون`, `قيمة`, and concrete Faber types
# • the `@جسون` annotation for custom field naming and genus-level JSON configuration
# • roundtrip serialization with `json.stringify()` and deserialization with `json.parse()`
#
# Common mistakes:
# • Applying @ جسون to a non-genus declaration — @ جسون is only supported on صنف declarations and their fields.
#
# See also:
# =============================================================================
import from "norma:json" جسون
@ جسون { }
class Payload {
@ جسون { name = "wire_name" }
var string name
}
main {
const جسون literal ← { "wire_name": "Ada", "items": [1, { "ok": true }] }
const value broad ← literal ↦ value
const جسون narrowed ← broad ↦ جسون
const Payload payload ← narrowed ↦ Payload
const جسون encoded ← payload ↦ جسون
const string wire ← json.stringify(encoded)
const جسون ∪ none tentativa ← json.try_parse(wire)
print payload.name
print wire
print tentativa
do {
const جسون reparsed ← json.parse(wire)
const Payload roundtrip ← reparsed ↦ Payload
print roundtrip.name
}
catch err {
print err
}
}