j5ml
J5ML is a JSON representation of a markup tree.
use ;
let node = from_str.unwrap;
let element = node.as_element.unwrap;
assert_eq!;
assert_eq!;
Markup describes trees. JSON describes data. J5ML is for documents that have to do both at once.
It is JsonML, widened for trees that are not XML. Every valid JsonML document is a valid J5ML document.
What it adds: an attribute value may be any JSON value, including an array or an object, where JsonML's grammar allows only string, number, true, false, and null. And from_str accepts JSON5, so a hand-authored document may carry comments, trailing commas, and unquoted keys:
let node = from_str.unwrap;
assert_eq!;
Serialization is always canonical JSON, never JSON5, so anything this crate writes is readable by a plain JSON parser. Use from_json_str when JSON5 syntax should be an error.
Names are preserved verbatim, so Gauge, ratio_bind, data-bind, and svg:circle all survive a round trip unchanged.
Attribute names are ordered on serialization, including keys nested inside an attribute value, so two implementations emit the same bytes for the same tree. Attributes live in a BTreeMap, so this is the natural order rather than a sorting pass.
J5ML is a format, not a policy. It does not define which names are legal, what they mean, or whether a document is safe to render. A consumer that renders J5ML into a medium where markup is executable must sanitize it first.
Node::walk is the traversal that check is built on. It visits a node and every descendant, parents before children, handing the visitor each node's Path so a rejection can say where. Return Walk::SkipChildren to leave a subtree alone, or Walk::Stop to end at the first finding.
use ;
let tree = from_str.unwrap;
let mut found = None;
tree.walk;
assert_eq!;
See spec/j5ml.md in the repository for the format, and spec/conformance-tests.json for the shared corpus every implementation is asserted against.
If you are round-tripping XML, jsonml implements the original grammar faithfully and is the better fit.
License
MIT OR Apache-2.0.