Module rsonpath_lib::classification::structural
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.
Classifying Commas
and Colons
is disabled by default.
It can be enabled on demand by calling
StructuralIterator::turn_commas_on
/StructuralIterator::turn_colons_on
.
This configuration is persisted across stop
and
resume
calls.
A structural classifier needs ownership over a base
QuoteClassifiedIterator
.
Examples
use rsonpath_lib::classification::structural::{Structural, classify_structural_characters};
use aligners::AlignedBytes;
let json = r#"{"x": [{"y": 42}, {}]}""#;
let aligned = AlignedBytes::new_padded(json.as_bytes());
let expected = vec![
Structural::Opening(0),
Structural::Opening(6),
Structural::Opening(7),
Structural::Closing(15),
Structural::Opening(18),
Structural::Closing(19),
Structural::Closing(20),
Structural::Closing(21)
];
let quote_classifier = rsonpath_lib::classification::quotes::classify_quoted_sequences(&aligned);
let actual = classify_structural_characters(quote_classifier).collect::<Vec<Structural>>();
assert_eq!(expected, actual);
use rsonpath_lib::classification::structural::{Structural, classify_structural_characters};
use rsonpath_lib::classification::quotes::classify_quoted_sequences;
use aligners::{alignment, AlignedBytes};
let json = r#"{"x": "[\"\"]"}""#;
let aligned = AlignedBytes::new_padded(json.as_bytes());
let expected = vec![
Structural::Opening(0),
Structural::Closing(14)
];
let quote_classifier = 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.