Module rsonpath_lib::classify

source ·
Expand description

Classification of structurally significant JSON bytes.

Provides the Structural struct and StructuralIterator trait that allow effectively iterating over structural characters in a JSON document.

A structural classifier needs ownership over a base QuoteClassifiedIterator.

Examples

use rsonpath_lib::classify::{Structural, classify_structural_characters};
use aligners::{alignment, AlignedBytes};

let json = r#"{"x": [{"y": 42}, {}]}""#;
let aligned = AlignedBytes::<alignment::Twice<rsonpath_lib::BlockAlignment>>::new_padded(json.as_bytes());
let expected = vec![
    Structural::Opening(0),
    Structural::Colon(4),
    Structural::Opening(6),
    Structural::Opening(7),
    Structural::Colon(11),
    Structural::Closing(15),
    Structural::Opening(18),
    Structural::Closing(19),
    Structural::Closing(20),
    Structural::Closing(21)
];
let quote_classifier = rsonpath_lib::quotes::classify_quoted_sequences(&aligned);
let actual = classify_structural_characters(quote_classifier).collect::<Vec<Structural>>();
assert_eq!(expected, actual);
use rsonpath_lib::classify::{Structural, classify_structural_characters};
use aligners::{alignment, AlignedBytes};

let json = r#"{"x": "[\"\"]"}""#;
let aligned = AlignedBytes::<alignment::Twice<rsonpath_lib::BlockAlignment>>::new_padded(json.as_bytes());
let expected = vec![
    Structural::Opening(0),
    Structural::Colon(4),
    Structural::Closing(14)
];
let quote_classifier = rsonpath_lib::quotes::classify_quoted_sequences(&aligned);
let actual = classify_structural_characters(quote_classifier).collect::<Vec<Structural>>();
assert_eq!(expected, actual);

Enums

Defines structural characters in JSON documents.

Traits

Trait for classifier iterators, i.e. finite iterators of Structural characters that hold a reference to the JSON document valid for 'a.

Functions

Walk through the JSON document represented by bytes and iterate over all occurrences of structural characters in it.
Resume classification using a state retrieved from a previously used classifier via the stop function.