Skip to content

Commit

Permalink
Fix issue 5 by iterating over the "seek" array.
Browse files Browse the repository at this point in the history
  • Loading branch information
willyboy authored Feb 12, 2018
1 parent dbb8e63 commit 3165cdf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/jsonpath-object-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,18 @@
var subpath = pathArr[1];
var path = pathArr[0];
var seek = jsonPath.eval(data, path) || [];
var mergeArray = pathArr[2] && pathArr[2].merge;

if (seek.length && subpath) {
result[key] = [];
seek[0].forEach(function(item, index) {
walk(item, subpath, result[key], index);
seek.forEach(function(items, seekIndex) {
items.forEach((item, itemIndex) => {
// itemIndex/seekIndex + 1 is so we are never multiplying by 0 which would throw off where the items should go
// subtract one after getting the index to rebase to 0
walk(item, subpath, result[key], (itemIndex + 1) * (seekIndex + 1) - 1);
});
});
if(pathArr[2] && pathArr[2].merge) {
if(mergeArray) {
// merge the individual objects in the array into one big object if the merge option is set to true
result[key] = result[key].reduce((reduced, el) => {
return Object.assign(reduced, el);
Expand Down

0 comments on commit 3165cdf

Please sign in to comment.