-
Notifications
You must be signed in to change notification settings - Fork 73
Open
Description
Hello!
I have a use case where I'm trying to transform a key in a deeply nested array + object structure. See example below:
var objectMapper = require('object-mapper');
var map = {
'[].data.children[].person_id': {key: 'entity[].humans.children[].person.id', transform: (e) => e+'_+1'},
};
var arr = [{
"id": "1",
"data": {
"children": [
{
"person_id": "123123123"
},
{
"person_id": "12312312"
},
{
"relation_id": "111"
}
]
}
}];
var dest = objectMapper(arr, map);
console.log(JSON.stringify(dest, null, 4))I was expecting an output of:
{
"entity": [ {
"humans": {
"children": [ {
"person": {
"id": "123123123_+1"
}
},
{
"person": {
"id": "12312312_+1"
} } ]
}
} ]
}Instead, I get:
{
"entity": [ {
"humans": {
"children": [ {
"person": {
"id": "123123123,12312312_+1_+1"
}
}
]
}
}
]}I'm doing some further debugging now, but it appears the transform() function gets called multiple times in the array iteration.
EmmanuelRoux, brunomillerps, denisdnc, ailushyk and ashlog
Metadata
Metadata
Assignees
Labels
No labels