packages

json

0.1.0공식

JSON (RFC 8259): Value tree, strict parser, streaming tokenizer, typed encode/decode, JSON Pointer

공개 · MIT OR Apache-2.0 · 의존성 0개

공식 패키지: use json::..;만 쓰면 첫 빌드가 추가합니다. 또는:

nabi add json

그다음 코드에서

use json::Value;
deps: {
    "json": Dep::version("^0.1.0"),
},

CI packages.nabi-lang.org License: MIT OR Apache-2.0

JSON (RFC 8259) for Nabi: a Value tree, a strict parser with line:col errors, compact and indented writers, a streaming tokenizer for large inputs, typed conversion with #[derive(Json)], and JSON Pointer. The API follows std's nabion module: parse / to_str / from_str / to_value / from_value, with ToJson / FromJson traits.

Add it

nabi add json

Needs Nabi 0.1 or later.

Usage

let v = try json::parse("{\"name\": \"geom\", \"sizes\": [1, 2.5, 12345678901234567890]}");
println(v.get("name")?.as_str() ?? "");          // geom
let big = v.pointer("/sizes/2")?.as_int() ?? 0;  // 12345678901234567890 (exact)
println(v.to_pretty(2));

Derive Json on your own types for typed from_str / to_str, and read large inputs event by event with Tokenizer.

parse reads text straight into a Value: strings are found with vectorized scans and, when they hold no escapes, share the input's bytes instead of copying them; floats are read by the Eisel-Lemire method (correctly rounded, the exact fallback only for the rare cases it cannot decide). An invalid document is read again by the tokenizer for the line:col error, so errors cost nothing on the happy path.

Docs

https://packages.nabi-lang.org/packages/json/latest/docs

License

Licensed under either of MIT or Apache-2.0, at your option. tests/jsontestsuite.txt is from JSONTestSuite, MIT License, Copyright (c) 2016 Nicolas Seriot.

README 출처: github.com/nabi-lang/json, 커밋 5434ad69.