Module
std.x.json — JSON as a QUERY, over the s40 kernel builtins: is this text valid, what is at this path, what kind is it, how many children does it have, and give it to me as the wolf type I expect. Stability tier: x (nursery, D31).
## The nursery banner (D31) — read this before you depend on it
**std.x.* is not std.*.** A module under x is a RESIDENT rather than a facade member — its path, its names, its rows and its behaviour may change or disappear in a single sprint, and no other std module may depend on one. std/x/README.md is the register: every resident is listed there with the measured reason it is not in the facade and the named trigger that graduates it.
The graduation clock. At every campaign closeout each resident is reviewed and one of three things happens, recorded in that closeout: it GRADUATES (it moves under std., and because the path *is* the API, the move is the release note), it is DELETED (the reviewed contract in its header is what survives), or it is EXTENDED by one campaign with a written reason. Nothing sits in x unexamined.
This module's clock starts at the stdc02 closeout, which is this campaign's. Its named triggers are below.
## Why the first tenant is json
D31 said the nursery's first tenant would be a json module, and s40 built the kernel for it — but the reason it is a resident rather than a member is measured, not decreed, and it is two reasons:
1. Unequal lanes — and the count MOVED at sc15. json_valid/ json_get/json_type/json_len were the checked tier's alone from s40 until this sprint's pin. s107 crossed the family natively (wolf_rt::json, a hand mirror of wolf_mem::json — the locked crate graph forbids reuse — with the two copies pinned upstream by the driver's json_parity test), so BOTH compiler rungs execute every function here now. lupin still declines the surface by design ("rather than risk a second, guessed RFC 8259 reading") while wolf-interp's own reading lands (is18, concurrent with this sprint); its column flips on a pin bump, never on an edit here. The graduation trigger was the native mirror plus the interpreter's own — the same two-consumer shape every builtin tier goes through. The first clause FIRED at this pin; the second is in flight, and the register records both. 2. This is a query surface, not the API json will end up with. A dotted path is a small language and it cannot express what the document can hold: a key containing . is unreachable at this tier (documented upstream and here), there is no way to enumerate an object's keys, and every read re-parses the whole text. The API a program eventually wants is std.json's DOM — one parse, a value you navigate — and that module has been complete in both directions since sc14 (see the sibling note below). What THIS module grew at sc15 is the compiled lanes' counterpart: the Node half below, a navigable handle over the same four kernels, because std.json's Value is an enum only the interpreter executes (F-0029) and the kernels now execute everywhere else. Whether a query face lives on beside the DOM or is deleted in favour of it is still a closeout's decision, and this is where it is written down.
## std.x.json and std.json are two modules, and what separates ## them MOVED at this pin
For five sprints module identity was the LAST path segment (F-0034), so use std.json beside use std.x.json was E0306 on both compiler rungs (F-0058's import half). s108 probe-closed that (wolf-lang#29): identity is the FULL path now, and the pair RESOLVES on all three lanes — the leaf-name clash is only a binding clash, and use std.x.json as xj names the second binding, exactly as the E0306 suggestion says. Measured at these pins, both directions: what stops a co-importing program today is the LANES, not the names — it dies at the first std.json body on the compiler rungs ("methods on generic std data") and at the first json_* under lupin. So every test and doc example here still imports exactly one module, and the two halves still compose at the TEXT level: text_of of a container is a document std.json.parse reads, and stringify writes a document root reads.
They divide the work the way their lanes do. std.json owns the DOM — a Value enum you build, NAVIGATE and serialize. Navigation arrived there at sc13: F-0037 (an enum returned through an error row takes the miss path on every call) closed at lupin 0.1.10 and json.get/at ship, so the sentence this paragraph carried for three sprints — "the DOM cannot be walked" — is retired; parse arrived at sc14 and the DOM is complete in both directions. This module owns the read direction — text in, wolf values out — and cannot build anything, because the kernel is queries only. The lanes divide the same way the work does: std.json's Value executes on the interpreter alone (F-0029), while everything here executes exactly where the kernels do — both compiler rungs at this sprint's pin, lupin pending is18.
Which means the graduation question this module's clock asks gets sharper rather than easier. The register says x.json either graduates as the streaming QUERY face beside std.json's DOM or is deleted in favour of it; the DOM answered parse at sc14, and at sc15 this module answered back with the Node half, so the question is symmetric now: two complete read surfaces, one per lane family. Nothing about the banner, the clock or the trigger changes here — this is a note for whoever holds the closeout, written where they will be standing.
## The tier this delegates to
Capability-free. The json_* builtins are the one pure builtin family: no I13 capability, no sandbox category, nothing reached. A package that uses only this module and the language declares no capability at all. The comptime engine still refuses them — there is no json evaluator in the D33 allowlist at v0, which is a design decision and not a capability question.
And that refusal is the one thing in this repository that cannot be held as a test. tests/{net,time,env}/comptime_refuses.lu each pin their tier's D33 rejection as fail(E0701) with the sandbox table's own sentence ("reaches the clock, which comptime code can never touch"). A comptime fn calling json_valid answers a bare unsupported at resolve — no code, no reason string, nothing in the record's diagnostics — so there is no directive to write it against and a package author learns nothing about why. Filed as F-0060; there is deliberately no comptime_refuses.lu here rather than a file asserting something weaker than the truth.
Paths are dotted segments. "" is the root; a segment of digits indexes an array; anything else keys an object. "users.0.name" is the second element's name. The node's KIND is what decides — on an object every segment is a key, digits included, so a member spelled "0" is reachable (measured; dom_navigation.lu pins it) — which is also why the DOM half's member/element can be typed at all. Build a path with child/child_index rather than by hand. **A key containing . is unreachable** — the tier says so and so does this module; it is not a bug to work around here, it is the ceiling of a dotted path, and it is one of the reasons the DOM is where json is going.
The rows are the toolchain's, verbatim (§14's rule, and this module adds no translation layer): parse for any RFC 8259 violation in the DOCUMENT, missing for a path that addresses nothing, kind for a node of the wrong kind for the operation. Two tags are this module's own and they are marked as such below: kind is reused for "the node is a number and you asked for an integer", and overflow (§10's mark) for a number outside the wolf type you asked for. Nothing here traps — a document is data, and every failure a document can cause is a row.
Numbers keep their source spelling in the kernel and this module is where they become wolf values: int_at reads an integer exactly, so a 64-bit id survives — std.json's number posture, arrived at from the other direction. The f64 half is a contract below and the reason is measured, not principled.
A repeated key is last-wins, one member per key (wolf-lang [os.json.dup], rulings B22 and #61, wolf-lang#124; it retires F-0088). A JSON object is a map: len counts names, not occurrences. An object holds one member per name, at the position where the name first appears, with the value of its LAST occurrence: get on {"a": 1, "a": 2} at "a" is 2 and len of that object is 1, which is what std.json.parse (a Map assignment) answers for the same text, so the two read surfaces now agree. A path walks through the last container a repeated name holds, and text_of a nested object carries the name once; the root's text is the document's own, repeats included. The kernels answered FIRST-wins and counted every repeat through wolf 0.2.26 / lupin 0.1.49; tests/x/json/dom_typed_reads.lu holds the ruled reading.
Every read re-parses the document. get on a ten-megabyte text is a ten-megabyte parse, and ten reads are ten parses. That is the kernel's shape, not a defect this module can hide, and it is the second-loudest argument for the DOM. Read a subtree once with get (which hands back a valid JSON text) and query THAT, if the shape of your data allows it. **The Node half below does not change the cost**: a Node is an ADDRESS — a document and a path — not a materialization, so each accessor is one more parse. What it buys is checked construction: a Node this module handed out addresses a node that existed, in a document that parsed, with the misses raised where the navigation happened rather than at every later read.
Reviewed contracts, blocked at the tier below:
float_at(doc: str, path: str) -> f64 ! {parse, missing, kind, overflow}
The number at `path` as `f64`, widening an integer node, with
`std.fmt.decimal.parse_float`'s correct rounding. WRITTEN, and
withdrawn before it shipped, for a reason that is arithmetic
rather than design: `parse_float` is `unsupported` on BOTH
compiler rungs ("arithmetic outside integers" at the mem tier —
F-0026's f64 ceiling, one body deep), and the checked tier is
this module's ONLY executing lane. So the function would have
had zero lanes and zero evidence: no test could run it, no doc
example could be fenced, and §14's doc-truth floor ("at least
one lane reaches exit(0)") would have been missed on every one.
A std function nobody can run is a claim, not code. It lands the
day either compiler rung executes `parse_float`, with this
signature and a four-line body; `get` plus the caller's own
conversion is the spelling until then.
keys(doc: str, path: str) -> List[str] ! {parse, missing, kind}
An object's member names. No builtin enumerates them — `json_len`
counts members and nothing names them — so an object can be
counted and not walked, which is the sharpest hole in the query
tier. **This is sc15's NAMED STOP**: the `Node` half below
inherits the hole whole (`keys_of` is the same contract over a
handle), s107 added no enumeration kernel, and the ask is written
rather than worked around — `json_keys(doc, path) -> List[str]
! {parse, missing, kind}`, the `fs_read_dir` shape one tier over
(F-0087, filed upstream). Blocked, not unwritten.
items(doc: str, path: str) -> List[str] ! {parse, missing, kind}
An array's elements as sub-documents. Writable TODAY over
`json_len` plus `child_index` plus `get` in a loop, and left out
deliberately: it would parse the document once per element, which
is quadratic in a shape programs reach for constantly, hidden
behind one call. sc15's `element` reads ONE element per call, so
the walk a caller writes — `len_of` plus `element` in a loop —
costs the same and shows the cost at the call site. A
list-returning `items` still waits for a cursor in the tier.
parse(doc: str) -> Value · stringify(v: Value) -> str
The DOM directions, both `std.json`'s. `stringify` shipped at
sc05, `get`/`at` at sc13 and `parse` at sc14 — that DOM is
complete. At sc15 THIS module grew its own `Node` face beside the
query functions: the compiled lanes' DOM, over the kernels, with
`root` as its entry point (not `parse` — see `root`'s doc for the
F-0036 reason).
Functions and methods
fn · Source line 244
pub fn is_valid(doc: str) -> bool
Whether doc is one well-formed RFC 8259 text.
Total: no rows, no traps — the one function here that answers for every input, which is what makes it the guard the others are written behind. Strict: no comments, no trailing commas, no bare identifiers, exactly one value with only insignificant whitespace around it, and container nesting limited (the kernel's limit is 128, and exceeding it is invalidity rather than a stack fault).
Capability-free; refused at comptime (D33 — no json evaluator, not a capability). Delegates to json_valid.
json.is_valid("[1, 2, 3]") == true
json.is_valid("{{\"a\": 1}}") == true
json.is_valid("[1,]") == false
json.is_valid("{{") == false
json.is_valid("") == false
fn · Source line 273
pub fn get(doc: str, path: str) -> str ! {parse, missing}
The node at path, rendered as text.
A string node comes back DECODED (escapes resolved, so "a\nb" is two lines and not four characters); a number keeps its source spelling exactly, so nothing is rounded on the way out; true, false and null spell themselves; an object or array comes back as JSON text — a valid document in its own right, which is what makes get(get(doc, "a"), "b") work and is the cheapest way to query a subtree twice.
Rows: parse when doc is not valid JSON, missing when nothing is at path. Never traps.
Bare get is the checked-access spelling and this one can miss (§1).
Capability-free; refused at comptime (D33). Delegates to json_get.
(json.get("{{\"a\": 1}}", "a") else "?") == "1"
(json.get("[10, 20]", "1") else "?") == "20"
(json.get("{{\"s\": \"hi\"}}", "s") else "?") == "hi"
(json.get("{{\"a\": {{\"b\": 2}}}}", "a.b") else "?") == "2"
(json.get("{{\"a\": 1}}", "b") else "?") == "?"
(json.get("{{", "a") else "?") == "?"
fn · Source line 299
pub fn type_name(doc: str, path: str) -> str ! {parse, missing}
The kind of the node at path — one of "object", "array", "str", "num", "bool", "null".
Rows: parse, missing. Never traps.
Spelled type_name and not kind for the reason std.json learned the hard way: a function and a row tag with the same name in one module make the tag resolve to the FUNCTION at the raise site, silently (F-0036). The names here are the kernel's own vocabulary ("str" and "num", not RFC 8259's "string" and "number"), adopted verbatim per §14 rather than prettified into a second dialect.
Capability-free; refused at comptime (D33). Delegates to json_type.
(json.type_name("{{\"a\": [1]}}", "a") else "?") == "array"
(json.type_name("{{\"a\": [1]}}", "a.0") else "?") == "num"
(json.type_name("{{\"a\": \"x\"}}", "a") else "?") == "str"
(json.type_name("{{\"a\": null}}", "a") else "?") == "null"
(json.type_name("{{\"a\": true}}", "a") else "?") == "bool"
(json.type_name("{{\"a\": {{}}}}", "a") else "?") == "object"
fn · Source line 324
pub fn len(doc: str, path: str) -> int ! {parse, missing, kind}
How many elements an array has, or members an object has, at path. A name an object repeats is one member (ruling #61: len counts names).
Rows: parse, missing, and kind for a scalar — a number has no length, and answering 1 or 0 would be a guess about which question was asked. Never traps.
Not a string length: len of a "str" node is kind, and the length of the text it holds is std.str.len of what get returns (§1: one concept, one home).
Capability-free; refused at comptime (D33). Delegates to json_len.
(json.len("[1, 2, 3]", "") else -1) == 3
(json.len("{{\"a\": 1, \"b\": 2}}", "") else -1) == 2
(json.len("[[1, 2]]", "0") else -1) == 2
(json.len("[]", "") else -1) == 0
(json.len("[1]", "0") else -1) == -1
fn · Source line 348
pub fn has(doc: str, path: str) -> bool ! {parse}
Whether doc has a node at path.
Rows: parse when the document is not valid JSON — a question about a path has no honest answer when the text is not a document, and false would say "no such field" about a file that is not JSON at all. Never traps.
has rather than contains for a keyed lookup (§8's vocabulary).
Capability-free; refused at comptime (D33). Delegates to json_valid and json_get.
(json.has("{{\"a\": 1}}", "a") else false) == true
(json.has("{{\"a\": 1}}", "b") else false) == false
(json.has("{{\"a\": null}}", "a") else false) == true
(json.has("[1, 2]", "1") else false) == true
(json.has("[1, 2]", "9") else false) == false
(json.has("nope", "a") else true) == true
fn · Source line 371
pub fn str_at(doc: str, path: str) -> str ! {parse, missing, kind}
The text of the string node at path, decoded.
Rows: parse, missing, and kind when the node is not a string. No coercion: str_at of a number is a miss and not "42", because a reader that guesses across JSON's types is a reader that loses the document's own information. get is the function that renders any node as text.
Capability-free; refused at comptime (D33).
(json.str_at("{{\"a\": \"wolf\"}}", "a") else "?") == "wolf"
(json.str_at("{{\"a\": \"line\\nbreak\"}}", "a") else "?") == "line\nbreak"
(json.str_at("{{\"a\": 1}}", "a") else "?") == "?"
fn · Source line 391
pub fn bool_at(doc: str, path: str) -> bool ! {parse, missing, kind}
The boolean at path.
Rows: parse, missing, kind for every non-boolean node. No coercion: 0, "" and null are all kind.
Capability-free; refused at comptime (D33).
(json.bool_at("{{\"a\": true}}", "a") else false) == true
(json.bool_at("{{\"a\": false}}", "a") else true) == false
(json.bool_at("{{\"a\": 0}}", "a") else false) == false
fn · Source line 413
pub fn is_null_at(doc: str, path: str) -> bool ! {parse, missing}
Whether the node at path is JSON null.
Rows: parse, missing. A predicate rather than a coercion, because "is this null" has a yes-or-no answer for every node that EXISTS — while an absent node is a different question, and it is missing.
Capability-free; refused at comptime (D33).
(json.is_null_at("{{\"a\": null}}", "a") else false) == true
(json.is_null_at("{{\"a\": 0}}", "a") else true) == false
(json.is_null_at("{{\"a\": null}}", "b") else true) == true
fn · Source line 447
pub fn int_at(doc: str, path: str) -> int ! {parse, missing, kind, overflow}
The integer at path, exactly.
Rows: parse, missing; kind when the node is not a number OR is a number that is not an integer (1.5, 1e3 and 1.0 are all kind — the document wrote a non-integer and this function will not round one); overflow (§10's mark) when the integer is outside int.
**overflow is a row and not a trap, and that is the whole reason this function does its own range check** rather than delegating straight to std.fmt.parse_int, which traps on an out-of-range value (correctly: to fmt the text is a caller's argument). Here the digits came out of a DOCUMENT — data, which §10 says raises where a caller's mistake traps — so a 20-digit id in someone's JSON is an outcome this function reports, never a process this function ends.
Exactness is the point: an id beyond 2^53 survives int_at and would not survive float_at. That is the same number posture std.json takes from the writing side.
Capability-free; refused at comptime (D33).
(json.int_at("{{\"a\": 42}}", "a") else -1) == 42
(json.int_at("{{\"a\": -7}}", "a") else 0) == -7
(json.int_at("{{\"a\": 9007199254740993}}", "a") else 0) == 9007199254740993
(json.int_at("{{\"a\": 1.5}}", "a") else -1) == -1
(json.int_at("{{\"a\": \"7\"}}", "a") else -1) == -1
(json.int_at("{{\"a\": 99999999999999999999}}", "a") else -1) == -1
fn · Source line 472
pub fn child(path: str, segment: str) -> str
path extended by one object key.
Total: no rows, no traps, and PURE — the only member of this module that reaches no builtin, so it is the only one a comptime program could use. An empty path is the root, so child("", "a") is "a".
A segment containing . produces a path that addresses something else, and this function does not pretend otherwise: there is no escape in the dotted-path language to hide behind (the module header's ceiling). Keys with dots need the DOM.
json.child("", "users") == "users"
json.child("users", "0") == "users.0"
json.child("a.b", "c") == "a.b.c"
fn · Source line 491
pub fn child_index(path: str, i: int) -> str
path extended by one array index.
Total: no rows, no traps, and PURE — comptime-safe. A negative index is not rejected here: it produces a path that addresses nothing, which is the missing row at the query, and one refusal in the right place beats two in the wrong one.
json.child_index("", 0) == "0"
json.child_index("users", 2) == "users.2"
json.child_index("a.0", 1) == "a.0.1"
fn · Source line 550
pub fn root(doc: str) -> Node ! {parse}
The root node of a well-formed document.
The DOM half's entry point: one validation, then a handle every later navigation and read composes from. Rows: parse when doc is not RFC 8259 — the only miss a root can have, since the root of a valid document always exists (missing is not on the signature because no argument can reach it).
**Spelled root and not parse, and the reason is F-0036's symmetric rule (sc14): a new pub fn is checked against its module's TAGS.** This module raises the kernel's parse tag throughout — has raises it by name, root itself does — and a tag that shares a name with anything in scope resolves to that thing silently. A pub fn parse here would capture every one of those raise sites, including its own body's. std.json hit the same collision from the other side and renamed its TAG (syntax); here the tag is the toolchain's verbatim and cannot move, so the FUNCTION yields the name.
Capability-free; refused at comptime (D33). Delegates to json_valid.
let r = json.root("{{\"a\": 1}}")?
(json.type_of(r) else "?") == "object"
let scalar = json.root(" 42 ")?
(json.int_of(scalar) else -1) == 42
fn · Source line 572
pub fn node(doc: str, path: str) -> Node ! {parse, missing}
The node at path — the bridge between the two halves: a dotted path built with child/child_index (or received as data) becomes a handle the DOM half reads.
Rows: parse when doc is not RFC 8259, missing when the path addresses nothing. Never traps.
Capability-free; refused at comptime (D33). Delegates to json_type.
let n = json.node("{{\"a\": {{\"b\": 2}}}}", "a.b")?
(json.int_of(n) else -1) == 2
let whole = json.node("[10, 20]", "")?
(json.len_of(whole) else -1) == 2
fn · Source line 601
pub fn member(n: Node, key: str) -> Node ! {parse, missing, kind}
The member node at key of an object node.
Rows: kind when n is not an object — member is the TYPED navigation, so asking an array or a scalar for a member is a wrong kind and not a silent miss; missing when the object has no entry at key; parse and missing also cover a forged n (see Node). Never traps.
The predicate spelling is the query half's has (§1: a question with a boolean answer keeps its predicate): has(n.doc, child(n.path, key)) answers without building the handle a caller does not want.
A key containing . addresses along the dots — the path ceiling, stated on Node and held as a test, not worked around here.
Capability-free; refused at comptime (D33). Delegates to json_type.
let r = json.root("{{\"pack\": [{{\"name\": \"lupin\"}}]}}")?
let pack = json.member(r, "pack")?
let leader = json.element(pack, 0)?
let name = json.member(leader, "name")?
(json.str_of(name) else "?") == "lupin"
fn · Source line 633
pub fn element(n: Node, i: int) -> Node ! {parse, missing, kind}
The element node at index i of an array node.
Rows: kind when n is not an array — an object with a member spelled "0" is reached by member, never by element, so the two navigations cannot be confused; missing when i is outside the array (a negative i is the same miss and not a from-the-end read — at's rule in std.json, held here too); parse and missing also cover a forged n. Never traps: the index came out of a walk over a DOCUMENT, and §10 says data raises where a caller's mistake traps.
The traversal this module has is len_of plus element in a loop — one parse per element, the kernel's cost at the call site where the caller can see it. There is no iterator surface here and none is coming at this tier (ruled territory).
Capability-free; refused at comptime (D33). Delegates to json_type.
let r = json.root("[10, 20, 30]")?
let second = json.element(r, 1)?
(json.int_of(second) else -1) == 20
fn · Source line 658
pub fn type_of(n: Node) -> str ! {parse, missing}
The kind of the node — one of "object", "array", "str", "num", "bool", "null"; the kernel's vocabulary, verbatim, and type_name's answer over a handle.
Rows: parse, missing — unreachable for a module-built Node, honest for a forged one. Never traps.
Capability-free; refused at comptime (D33). Delegates to json_type.
let r = json.root("{{\"a\": [1]}}")?
(json.type_of(r) else "?") == "object"
let a = json.member(r, "a")?
(json.type_of(a) else "?") == "array"
fn · Source line 688
pub fn text_of(n: Node) -> str ! {parse, missing}
The node rendered as text — get's answer over a handle: a string node comes back DECODED, a number keeps its source spelling, true, false and null spell themselves, and a container comes back as JSON text, a valid document in its own right. That last case is how this half composes with std.json: text_of of a container is a text its parse reads, exactly as its stringify writes a text root reads (in prose because one program cannot import both — the two modules share a leaf name, F-0058).
A nested container may be re-rendered compactly rather than sliced from the source (the kernel's documented shape); it is the same document either way.
Rows: parse, missing — forged-Node tags, as on type_of. Never traps.
Capability-free; refused at comptime (D33). Delegates to json_get.
let r = json.root("{{\"a\": [1, 2]}}")?
let a = json.member(r, "a")?
(json.text_of(a) else "?") == "[1,2]"
let t = json.text_of(a) else "?"
let sub = json.root(t)?
(json.len_of(sub) else -1) == 2
fn · Source line 709
pub fn len_of(n: Node) -> int ! {parse, missing, kind}
How many elements an array node has, or members an object node has. A name an object repeats is one member (ruling #61).
Rows: kind for a scalar — a number has no length, and answering 0 or 1 would be a guess about which question was asked (len's rule, over a handle); parse, missing for a forged Node. Never traps.
Capability-free; refused at comptime (D33). Delegates to json_len.
let r = json.root("[1, 2, 3]")?
(json.len_of(r) else -1) == 3
let empty = json.root("{{}}")?
(json.len_of(empty) else -1) == 0
let scalar = json.root("42")?
(json.len_of(scalar) else -1) == -1
fn · Source line 729
pub fn str_of(n: Node) -> str ! {parse, missing, kind}
The text of a string node, decoded.
Rows: kind when the node is not a string — no coercion, ever: str_of of a number is a miss and not "42", because a reader that guesses across JSON's types loses the document's own information (str_at's rule, over a handle); parse, missing for a forged Node. Never traps. text_of is the function that renders ANY node.
Capability-free; refused at comptime (D33).
let n = json.node("{{\"s\": \"line\\nbreak\"}}", "s")?
(json.str_of(n) else "?") == "line\nbreak"
let wrong = json.node("{{\"s\": 1}}", "s")?
(json.str_of(wrong) else "?") == "?"
fn · Source line 749
pub fn bool_of(n: Node) -> bool ! {parse, missing, kind}
The boolean a bool node holds.
Rows: kind for every non-boolean node — 0, "" and null are all kind, no coercion (bool_at's rule, over a handle); parse, missing for a forged Node. Never traps.
Capability-free; refused at comptime (D33).
let n = json.node("{{\"on\": true}}", "on")?
(json.bool_of(n) else false) == true
let off = json.node("{{\"on\": false}}", "on")?
(json.bool_of(off) else true) == false
let zero = json.node("{{\"on\": 0}}", "on")?
(json.bool_of(zero) else false) == false
fn · Source line 771
pub fn int_of(n: Node) -> int ! {parse, missing, kind, overflow}
The integer a number node holds, exactly.
Rows: kind when the node is not a number OR is a number that is not an integer (1.5, 1e3 and 1.0 are all kind — the document wrote a non-integer and this function will not round one); overflow (§10's mark) when the integer is outside int — a row and not a trap, because the digits came out of a DOCUMENT; parse, missing for a forged Node. Exactness is the point: an id beyond 2^53 survives int_of. All of it is int_at's contract, over a handle.
Capability-free; refused at comptime (D33).
let n = json.node("{{\"id\": 9007199254740993}}", "id")?
(json.int_of(n) else 0) == 9007199254740993
let fraction = json.node("[1.5]", "0")?
(json.int_of(fraction) else -1) == -1
fn · Source line 790
pub fn is_null(n: Node) -> bool ! {parse, missing}
Whether the node is JSON null.
A predicate over a node that EXISTS, so it answers for every node — which is why it is not kind-rowed: "is this null" has a yes-or-no answer whatever the kind (is_null_at's rule, over a handle). Rows: parse, missing for a forged Node. Never traps.
Capability-free; refused at comptime (D33).
let n = json.node("{{\"a\": null}}", "a")?
(json.is_null(n) else false) == true
let zero = json.node("{{\"a\": 0}}", "a")?
(json.is_null(zero) else true) == false