A rust library for converting to and from XML and JSON.
bash
λ › cargo add xml2json-rs
XmlBuilder
builds XML from JSON.
- build_from_json
builds an XML String
from a serde_json::Value
.
- build_from_json_string
builds an XML String
from a serialized JSON String
.
```rust use xml2json::XmlBuilder; use std::error::Error;
fn main() -> Result<(), Box
XmlConfig
Uses the Builder pattern to set configuration options and then finalize
to
build an XmlBuilder
.
```rust use xml2json::XmlConfig; use xml2json::{ Indentation, Declaration, Version, Encoding }; use std::error::Error; use indoc::indoc;
fn main() -> Result<(), Box
let xml = xmlbuilder.buildfromjsonstring(r#"{"book":{"^":{"category":"fantasy"},"title":{"":"The Name of the Wind","^":{"lang":"en"}},"author":"Patrick Rothfuss","year":"2007"}}"#)?;
asserteq!(xml, indoc!(r#"
```
JsonBuilder
builds JSON from XML.
- build_from_xml
build a serde_json::Value
from an XML String
.
- build_string_from_xml
build a JSON serialized String
from an XML String
.
- build_pretty_string_from_xml
build a pretty-printed JSON serialized String
from an XML String
.
```rust use xml2json::JsonBuilder; use std::error::Error;
fn main() -> Result<(), Box
JsonConfig
Uses the Builder pattern to set configuration options and then finalize
to build an JsonBuilder
.
```rust use xml2json::JsonConfig; use std::error::Error;
fn main() -> Result<(), Box
This library was inspired by node-xml2json and has a primary objective of maintaining parity with its 0.4.20
version.
Integration tests are generated via scripts using node-xml2json
in order to verify parity.
bash
λ › cd tests/generator
λ › yarn
λ › ./generate
bash
λ › cargo test