Renderingen-US

json

Translation status: English reader-locale proof. Code fences render through the en pipeline; prose is canonical Latin.

Syntax:

Category#

type

None.

Examples#

radix/corpus/json/json.fab (canonical · type)#

# =============================================================================
# json — JSON serialization and deserialization
# =============================================================================
#
# What this teaches:
#   • JSON type conversions using `↦` — converting between `json`, `valor`, and concrete Faber types
#   • the `@json` annotation for custom field naming and genus-level JSON configuration
#   • roundtrip serialization with `json.pange()` and deserialization with `json.solve()`
#
# Common mistakes:
#   • Applying @ json to a non-genus declaration — @ json is only supported on genus declarations and their fields.
#
# See also:
# =============================================================================

import from "norma:json" private json

@ json
class Payload {
    @ json { nomen = "wire_name" }
    string name
}

main {
    const json literal  { "wire_name": "Ada", "items": [1, { "ok": true }] }
    const value broad  literal ↦ value
    const json narrowed  broad ↦ json

    const Payload payload  narrowed ↦ Payload
    const json encoded  payload ↦ json
    const string wire  json.pange(encoded)
    const json  null tentativa  json.tempta(wire)

    print payload.name
    print wire
    print tentativa

    do {
        const json reparsed  json.solve(wire)
        const Payload roundtrip  reparsed ↦ Payload
        print roundtrip.name
    }
    catch err {
        print err
    }
}