[](https://crates.io/crates/unstructured) [](https://docs.rs/unstructured/) [](LICENSE)
This library provides types for usage with unstructured data. This is based on functionality from both serdejson and serdevalue. Depending on your use case, it may make sense to use one of those instead.
These structures for serialization and deserialization into an intermediate container with serde and manipulation of this data while in this intermediate state.
So why not use one of the above libraries?
In addition to many of the futures provided by the above libraries, unstructured also provides:
Document::U64(100) == 100 as u64
doc1.merge(doc2)
or doc = doc1 + doc2
doc.select(".path.to.key")
docs.filter("[0].path.to.key | [1].path.to.array[0:5]")
The primary struct used in this repo is Document
. Document provides methods for easy type conversion and manipulation.
```rust use unstructured::Document; use std::collections::BTreeMap;
let mut map = BTreeMap::new(); // Will be inferred as BTreeMap
Document implements serialize and deserialize so that it can be easily used where the data format is unknown and manipulated after it has been received.
```rust
extern crate serde; use unstructured::Document;
struct SomeStruct { key: String, }
fn main() { let fromservice = "{\"key\": \"value\"}"; let doc: Document = serdejson::fromstr(fromservice).unwrap(); let expected: Document = "value".into(); assert_eq!(doc["key"], expected);
let some_struct: SomeStruct = doc.try_into().unwrap();
assert_eq!(some_struct.key, "value");
let another_doc = Document::new(some_struct).unwrap();
assert_eq!(another_doc["key"], expected);
} ```
Selectors can be used to retrieve a reference to nested values, regardless of the incoming format.
doc.select("/path/to/key")
doc.select(".path.to.[\"key\"")
```rust use unstructured::Document;
let doc: Document =
serdejson::fromstr("{\"some\": {\"nested\": {\"value\": \"is this value\"}}}").unwrap();
let docelement = doc.select("/some/nested/value").unwrap(); // Returns an Option
In addition to selectors, filters can be used to create new documents from an array of input documents.
```rust use unstructured::Document;
let docs: Vec