Skip to main content

Crate reliakit_json

Crate reliakit_json 

Source
Expand description

Strict, bounded, and deterministic JSON for reliability-sensitive Rust.

reliakit-json is built for systems that process untrusted JSON or need predictable output: it parses a strict subset of RFC 8259, rejects duplicate object keys, enforces explicit resource limits, preserves number precision, reports errors with location and path, and serializes deterministically. It has no external dependencies, forbids unsafe code, and supports no_std (with alloc).

It deliberately does not provide derive macros, schema validation, JSON5, comments, trailing commas, lenient parsing, or SIMD throughput.

§Example

use reliakit_json::{parse_str, to_compact_string};

let value = parse_str(r#"{"name":"reliakit","ok":true}"#).unwrap();
assert_eq!(value.as_object().unwrap().get("name").unwrap().as_str(), Some("reliakit"));

// Serialization is deterministic and preserves member order.
assert_eq!(to_compact_string(&value), r#"{"name":"reliakit","ok":true}"#);

// Strict by default: duplicate keys are rejected, not silently resolved.
assert!(parse_str(r#"{"a":1,"a":2}"#).is_err());

§Limits

parse applies conservative JsonLimits by default. Use parse_with_limits to choose a profile or tune individual limits:

use reliakit_json::{parse_with_limits, JsonLimits};

let limits = JsonLimits::conservative().with_max_depth(8);
assert!(parse_with_limits(b"[[[[[[[[[[1]]]]]]]]]]", limits).is_err());

§Feature flags

  • std (default) enables std::error::Error for the error types. The crate is otherwise no_std and always uses alloc.
  • canonical enables RFC 8785 (JCS) canonical serialization.
  • primitives adds typed extraction into reliakit-primitives constrained types (JsonObject::get_str_as, JsonValue::str_as); it pulls in reliakit-primitives (no_std + alloc, zero third-party dependencies).

Structs§

JsonError
An error produced while parsing or serializing JSON.
JsonExtractError
An error from extracting a typed value out of JSON, carrying the JsonPath of the offending location.
JsonLimits
Resource limits enforced while parsing.
JsonMember
A single object member (key/value pair).
JsonNumber
A JSON number that preserves its exact, validated source representation.
JsonObject
A JSON object: members in insertion order with unique keys.
JsonPath
The location of an error within the JSON document, as a path of object keys and array indices from the document root ($).

Enums§

JsonErrorKind
The category of a parse or serialization failure.
JsonExtractErrorKind
Why extracting a typed reliakit-primitives value from JSON failed.
JsonLimitKind
A resource limit that was exceeded while parsing.
JsonNumberError
An error from a JsonNumber conversion.
JsonPathSegment
One segment of a JsonPath.
JsonValue
An owned JSON value.

Functions§

parse
Parses a JSON value from UTF-8 bytes using the default JsonLimits.
parse_str
Parses a JSON value from a &str using the default JsonLimits.
parse_with_limits
Parses a JSON value from UTF-8 bytes with explicit JsonLimits.
to_canonical_string
Serializes a value to its RFC 8785 (JCS) canonical form as a String.
to_canonical_vec
Serializes a value to its RFC 8785 (JCS) canonical form as UTF-8 bytes.
to_compact_string
Serializes a value to a compact JSON string (no insignificant whitespace).
to_compact_vec
Serializes a value to compact JSON bytes. See to_compact_string.