json
On this page
JSON (RFC 8259). parse reads a document into a Value, to_str
/ to_pretty write one, and ToJson / FromJson (with
#[derive(Json)]) map Nabi types to and from Value, as std's
nabion does for NABION. Tokenizer reads large inputs as a stream of
Events.
Decode errors carry a JSON Pointer path (/servers/1/port);
from_str turns it into line:col by re-reading the document up to
that path, so the happy path keeps no positions.
Modules
Re-exports
read::{Event, Tokenizer, MAX_DEPTH}Source
pub use read::{Event, Tokenizer, MAX_DEPTH}Structs
JsonErrorSource
pub struct JsonErrorA read or decode error. line / col (1-based, code points) are 0
when the value did not come from text; path is a JSON Pointer to the
failing part (/servers/2/port, empty at the root).
selfone level down:seg(/name,/3) goes in front of the path.What went wrong, without the position.
1-based line, 0 when the value did not come from text.
1-based column in code points, 0 when the value did not come from text.
JSON Pointer to the failing part, empty at the root.
Trait implementations 3
impl Display for JsonErrorimpl Debug for JsonErrorimpl Error for JsonError
Enums
ValueSource
pub enum ValueA JSON value. Integers without a fraction or exponent are exact
(Int); other numbers are Float. Objects keep insertion order; a
repeated key keeps its first position and its last value.
Compact text. Panics on a NaN / infinite float.
Text with each member on its own line,
indentspaces per level (0isto_str).What kind of value this is, for messages.
Member
keyof an object.Item
iof an array.The value at JSON Pointer
p(RFC 6901):""is the whole value,/a/0memberathen item 0,~1/~0stand for//~.nonewhen there is no such value orpis malformed.A number as
f64(anIntrounds to the nearest).
Trait implementations 1
impl Display for Value
Traits
ToJsonSource
pub trait ToJsonA Nabi value as JSON.
FromJsonSource
pub trait FromJsonA Nabi value from JSON; the target type decides how v reads.
An object member of this type that the document leaves out: an error, except
T | none(none).
Functions
escape_tokenSource
pub fn escape_token(k: str) -> str k as a JSON Pointer reference token (~ -> ~0, / -> ~1).
parseSource
pub fn parse(s: str) throws (JsonError) -> Value Read one document (nesting up to MAX_DEPTH).
parse_tokensSource
pub fn parse_tokens(t: Tokenizer) throws (JsonError) -> Value Read one document from a tokenizer (set its max_depth first to
change the limit; Tokenizer::from_reader reads a stream).
to_strSource
pub fn to_str<T: ToJson>(x: T) -> str x as compact JSON. Panics on a NaN / infinite float.
to_prettySource
pub fn to_pretty<T: ToJson>(x: T) -> str x as JSON indented by 2 spaces.
from_strSource
pub fn from_str<T: FromJson>(s: str) throws (JsonError) -> T Read a document as a T; errors carry the line:col of the part
that did not fit.
to_valueSource
pub fn to_value<T: ToJson>(x: T) -> Value x as a Value.
from_valueSource
pub fn from_value<T: FromJson>(v: Value) throws (JsonError) -> T v as a T.