jsonpath-lz-transformer
v0.0.5
Published
Transform object to another with JSONPath
Downloads
4
Readme
jsonpath-transformer
This library allow you to transform an object with a jsonpath object definition. It is derivated from: .. that seems to not be maintained anymore. It was migrated to typescript in the process.
Install
yarn add jsonpath-transformer
Examples
import { Transformer } from "jsonpath-transformer";
// Source Object
let source = {
level1: {
sublevel1: {
sublevel2: {
attr1: "Attr_1",
},
array: [{ name: "Yop" }, { name: "Plop" }, { name: "Yop2" }],
},
},
}
// Mapper
let mapper = {
attr1: "$.level1.sublevel1.sublevel2.attr1",
array: ["$.level1.sublevel1.array", { test: "$.name" }],
}
// Result
let result = Transformer(source, mapper);
result === {
attr1: "Attr_1",
array: [{ test: "Yop" }, { test: "Plop" }, { test: "Yop2" }],
}