pub fn transform(input: Value, spec: &TransformSpec) -> Result<Value>Expand description
Perform JSON to JSON transformation where the “specification” is a JSON.
Inspired by Java library Jolt.
The transformation can compose of many operations that are chained together.
§Operations
shift: copy data from the input tree and put it the output treedefault: apply default values to the treeremove: remove data from the treemodify: modify data using functions like concat, toLower, etc.
For example, if you want to repack your JSON record, you can do the following:
use serde_json::{json, Value};
use harmony_jolt::{transform, TransformSpec};
let input: Value = serde_json::from_str(r#"
{
"id": 1,
"name": "John Smith",
"account": {
"id": 1000,
"type": "Checking"
}
}
"#).unwrap();
let spec: TransformSpec =
serde_json::from_str(r#"[
{
"operation": "shift",
"spec": {
"name": "data.name",
"account": "data.account"
}
}
]"#).unwrap();
let output = transform(input, &spec).unwrap();
assert_eq!(output, json!({
"data" : {
"name": "John Smith",
"account": {
"id": 1000,
"type": "Checking"
}
}
}));Checkout supported operations in TransformSpec docs.