Skip to main content

parse_to_dom

Function parse_to_dom 

Source
pub fn parse_to_dom<'a>(src: &'a str) -> Option<Dom<'a>>
Expand description

Parse src into a flat Dom using the portable SWAR classifier.

Returns None if the input is not valid JSON.

StartObject(n) / StartArray(n) entries carry the index of the matching closer so entire subtrees can be skipped in O(1). Access the tape via Dom::root which returns a DomRef cursor that implements JsonRef.

For maximum throughput on CPUs with AVX-512BW, use [parse_to_dom_zmm].

use asmjson::{parse_to_dom, JsonRef};
let tape = parse_to_dom(r#"{"x":1}"#).unwrap();
assert_eq!(tape.root().get("x").as_i64(), Some(1));