template-transformer
Node.js module that is used to transform jsons based on templates
Usage
const getTransformer = ; /** A template example */const template = simpleString:'string ' simpleNumber: 100 simpleBoolean: true simpleArray: 123 path: '$.a.b.c' 'arrayTransformed[$.array]': a: '$.b' index: '$.$index' parentValue: '$..a.b.c' array: '$.$array' simpleObject: pathFromAlternativeInput: '$1.a.b' /** a cb example */{ iftypeof input ==='string' return input; return input;} /** * The default dropValues used if not overwritten. * - Any value in this array will be removed. * - Empty arrays will be removed* - Empty objects will also be removed*/const dropValues = null undefined '';const transformer = > /* { "simpleString": "string", "simpleNumber": 100, "simpleBoolean": true, "simpleArray": [1, 2, 3], "path": "a value", "arrayTransformed": [ { "a": "test", "index": 0, "parentValue": "a value", "array": [{"b": " test "}, {"b": "another test"}] }, { "a": "another test", "index": 1, "parentValue": "a value", "array": [{"b": " test "}, {"b": "another test"}] } ], "simpleObject": { "pathFromAlternativeInput": "alternative value" }}*/
About
This work was inspired by jsonpath-object-transform and my work @Workable. More than 6 years of experience transforming jsons using templates and code resulted in this module. It tries to solve most common issues and difficulties people have when working with templates. This module was mostly developed during my flight to Brussels from Athens and back.