diff --git a/lib/JSON2CSVBase.js b/lib/JSON2CSVBase.js index 8d016702..b7d7d05e 100644 --- a/lib/JSON2CSVBase.js +++ b/lib/JSON2CSVBase.js @@ -234,8 +234,12 @@ class JSON2CSVBase { */ unwindData(dataRow, unwindPaths) { return unwindPaths - .reduce((data, unwindPath) => - data.map((dataEl) => { + .reduce((data, unwindPath) => { + function clone(o) { + return unwindPath.indexOf('.') !== -1 ? lodashCloneDeep(o) : Object.assign({}, o); + } + + return data.map((dataEl) => { const unwindArray = lodashGet(dataEl, unwindPath); if (!Array.isArray(unwindArray)) { @@ -244,7 +248,7 @@ class JSON2CSVBase { if (unwindArray.length) { return unwindArray.map((unwindEl, index) => { - const dataCopy = lodashCloneDeep(dataEl); + const dataCopy = clone(dataEl); if (this.opts.unwindBlank && index > 0) { Object.keys(dataCopy).forEach(key => { @@ -254,16 +258,16 @@ class JSON2CSVBase { }) } - lodashSet(dataCopy, unwindPath, unwindEl); return dataCopy; }); } - const dataCopy = lodashCloneDeep(dataEl); + const dataCopy = clone(dataEl); lodashSet(dataCopy, unwindPath, undefined); return dataCopy; - }).reduce((tempData, rows) => tempData.concat(rows), []), + }).reduce((tempData, rows) => tempData.concat(rows), []) + }, [dataRow] ) .reduce((tempData, rows) => tempData.concat(rows), []);