Skip to main content

Crate json_syntax

Crate json_syntax 

Source
Expand description

This library provides a strict JSON parser as defined by RFC 8259 and ECMA-404. Parsing values generates a [CodeMap] that keeps track of the position of each JSON value fragment in the parsed document.

§Features

  • Strict implementation of RFC 8259 and ECMA-404.
  • No stack overflow, your memory is the limit.
  • Numbers are stored in lexical form thanks to the json-number crate, their precision is not limited.
  • Duplicate values are preserved. A JSON object is just a list of entries, in the order of definition.
  • Strings are stored on the stack whenever possible, thanks to the smallstr crate.
  • The parser is configurable to accept documents that do not strictly adhere to the standard.
  • Highly configurable printing methods.
  • Macro to build any value statically.
  • JSON Canonicalization Scheme implementation (RFC 8785) enabled with the canonicalization feature.
  • serde support (by enabling the serde feature).
  • Conversion from/to serde_json::Value (by enabling the serde_json feature).
  • Thoroughly tested.

§Usage

use std::fs;
use json_syntax::{JsonValue, JsonParse, JsonPrint};

let filename = "tests/inputs/y_structure_500_nested_arrays.json";
let input = fs::read_to_string(filename).unwrap();
let mut value = JsonValue::parse_str(&input).expect("parse error").0;
println!("value: {}", value.pretty_print());

Re-exports§

pub use array::JsonArray;
pub use array::JsonArrayBuf;
pub use code_map::JsonCodeMap;
pub use kind::JsonKind;
pub use kind::JsonKindSet;
pub use number::InvalidJsonNumber;
pub use number::JsonNumber;
pub use number::JsonNumberBuf;
pub use object::JsonObject;
pub use parse::JsonParse;
pub use print::JsonPrint;
pub use string::JsonString;
pub use serde::from_slice;
pub use serde::from_str;
pub use serde::from_value;
pub use serde::to_value;
pub use locspan;
pub use ryu_js;

Modules§

array
code_map
kind
JSON value kinds.
lexical
number
object
parse
print
serde
string
tracing
Allocation-free source-location tracking (“backtraces”) for JsonValue.
visitor

Macros§

json
Constructs a json_syntax::JsonValue from a JSON literal.

Structs§

Traverse

Enums§

JsonFragment
JsonFragments
JsonValue
JSON Value.