JSON encoder + integer-field decoder for fastC.
Part of the fastc-core launch set. Implementation ships in the
fastC v1.0 prelude — use json::* works out of the box.
Builder model over an owned Str buffer:
use json::new_builder;
use json::obj_start;
use json::key;
use json::int_value;
use json::str_value;
use json::obj_end;
fn render() -> Str {
let b: JsonBuilder = new_builder();
obj_start(addrm(b));
key(addrm(b), cstr("id")); int_value(addrm(b), 42);
key(addrm(b), cstr("name")); str_value(addrm(b), cstr("alice"));
obj_end(addrm(b));
return (deref(addr(b))).out;
}
Produces {"id":42,"name":"alice"}.
find_int(text, key, fallback) — locate a top-level
"key": <integer> and return the parsed i64. Returns
fallback for absent keys, non-integer values, malformed JSON,
or keys nested below the top level.
use json::find_int;
let resp: raw(u8) = cstr("{\"id\": 42, \"count\": 7}");
let id: i64 = find_int(resp, cstr("id"), cast(i64, -1)); // 42
let absent: i64 = find_int(resp, cstr("x"), cast(i64, -1)); // -1
v1 covers the 80% "pull an int out of an HTTP response" case. Full DOM + streaming decoder lands when there's user demand.
v0.1.0 — preview. API is final.
MIT