jsonpath-object-transform
jsonpath-object-transform copied to clipboard
Value Pattern
Hello,
I would like to make a suggestion:
In addition to transform the structure of the object, it would be also possible to transform the value of the attributes.
For example: Original: { type: 'String' }
Transformed: { type: 'text' }
Hugs.
I think that would be great! However, I'm having trouble figuring out a clean way to add additional options to this thing because of how restricting the syntax is.
So I've been considering adopting a JSON Schema syntax instead:
var output = transformObject(input, {
type: 'object',
properties: {
firstDemo: {
type: 'string',
jsonPath: '$.example'
},
secondDemo: {
type: 'array',
items: {
type: 'string'
},
jsonPath: {
expression: '$..anotherExample',
visitor: function (value) {
return value.toUpperCase();
}
}
}
}
});
That would give me room to add features.
Another option would be to provide helper methods for generating the schema:
var output = jot(input).object({
firstDemo: jot
.string('$.example'),
secondDemo: jot
.array('string', '$..anotherExample')
.visitor(transformMyResults)
});
Your way would be better.
But I had to use a different approach to my scenario.
For example: I used a conversion map.
var transformValues = { type: { String: 'text' Boolean: 'checkbox' } }
Type: is attribute And the value of Type is the casts map.
And I call
transform (obj, template, transformValues);
But i know it has limitations, example, this method not consider full path of attribute, only the field name.
hugs