Skip to content

Commit bf4dd22

Browse files
authored
chore(release): 3.14.0 (#195)
* chore(release): 3.14.0 * Support keys with '.' characters in them (#194) * Add support for keys with nested dots. Through modifications to `doc-path` and `deeks` dependency underlying code, I've worked to add support for the keys with nested dots in the JSON key path and conversion back to CSV. This was achieved through the `deeks` module's new `escapeNestedDots` option which will now be set to `true`. Additionally, support for this escaping was added to `doc-path` so that the correct values are retrieved and can also be correctly set for csv2json. This commit adds the option specification for the `deeks` module and the updated versions of the dependency modules in package.json. Fixes #184
1 parent 2183282 commit bf4dd22

13 files changed

+180
-13
lines changed

lib/json2csv.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const Json2Csv = function(options) {
1212
expandingWithoutUnwinding = options.expandArrayObjects && !options.unwindArrays,
1313
deeksOptions = {
1414
expandArrayObjects: expandingWithoutUnwinding,
15-
ignoreEmptyArraysWhenExpanding: expandingWithoutUnwinding
15+
ignoreEmptyArraysWhenExpanding: expandingWithoutUnwinding,
16+
escapeNestedDots: true
1617
};
1718

1819
/** HEADER FIELD FUNCTIONS **/

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"name": "json-2-csv",
77
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
8-
"version": "3.13.0",
8+
"version": "3.14.0",
99
"homepage": "https://mrodrig.github.io/json-2-csv",
1010
"repository": {
1111
"type": "git",
@@ -39,8 +39,8 @@
3939
"cli"
4040
],
4141
"dependencies": {
42-
"deeks": "2.3.0",
43-
"doc-path": "2.3.0"
42+
"deeks": "2.4.1",
43+
"doc-path": "3.0.0"
4444
},
4545
"devDependencies": {
4646
"babel-eslint": "10.1.0",

test/config/testCsvFilesList.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ const fs = require('fs'),
4040
{key: 'emptyLastFieldValue', file: '../data/csv/emptyLastFieldValue.csv'},
4141
{key: 'emptyLastFieldValueNoEol', file: '../data/csv/emptyLastFieldValueNoEol.csv'},
4242
{key: 'lastCharFieldDelimiter', file: '../data/csv/lastCharFieldDelimiter.csv'},
43-
{key: 'nativeMapMethod', file: '../data/csv/nativeMapMethod.csv'}
43+
{key: 'nativeMapMethod', file: '../data/csv/nativeMapMethod.csv'},
44+
{key: 'nestedDotKeys', file: '../data/csv/nestedDotKeys.csv'},
45+
{key: 'nestedDotKeysWithArray', file: '../data/csv/nestedDotKeysWithArray.csv'},
46+
{key: 'nestedDotKeysWithArrayExpandedUnwound', file: '../data/csv/nestedDotKeysWithArrayExpandedUnwound.csv'}
4447
];
4548

4649
function readCsvFile(filePath) {

test/config/testJsonFilesList.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ module.exports = {
3030
firstColumnWrapCRLF: require('../data/json/firstColumnWrapCRLF.json'),
3131
emptyLastFieldValue: require('../data/json/emptyLastFieldValue.json'),
3232
emptyLastFieldValueNoEol: require('../data/json/emptyLastFieldValueNoEol.json'),
33-
nativeMapMethod: require('../data/json/nativeMapMethod.json')
33+
nativeMapMethod: require('../data/json/nativeMapMethod.json'),
34+
nestedDotKeys: require('../data/json/nestedDotKeys.json'),
35+
nestedDotKeysWithArray: require('../data/json/nestedDotKeysWithArray.json'),
36+
nestedDotKeysWithArrayExpandedUnwound: require('../data/json/nestedDotKeysWithArrayExpandedUnwound.json')
3437
};

test/csv2json.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,33 @@ function runTests(jsonTestData, csvTestData) {
198198
done();
199199
});
200200
});
201+
202+
// Test case for #184
203+
it('should properly convert keys with escaped/nested dots in them', (done) => {
204+
converter.csv2json(csvTestData.nestedDotKeys, (err, json) => {
205+
if (err) done(err);
206+
json.should.deepEqual(jsonTestData.nestedDotKeys);
207+
done();
208+
});
209+
});
210+
211+
// Test case for #184
212+
it('should properly convert keys with escaped/nested dots in them even when they appear in an array', (done) => {
213+
converter.csv2json(csvTestData.nestedDotKeysWithArray, (err, json) => {
214+
if (err) done(err);
215+
json.should.deepEqual(jsonTestData.nestedDotKeysWithArray);
216+
done();
217+
});
218+
});
219+
220+
// Test case for #184
221+
it('should properly convert keys with escaped/nested dots in them even when they appear in an expanded, unwound array', (done) => {
222+
converter.csv2json(csvTestData.nestedDotKeysWithArrayExpandedUnwound, (err, json) => {
223+
if (err) done(err);
224+
json.should.deepEqual(jsonTestData.nestedDotKeysWithArrayExpandedUnwound);
225+
done();
226+
});
227+
});
201228
});
202229

203230
describe('Error Handling', () => {

test/data/csv/nestedDotKeys.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a\.a,a\.b.c\.d,a\.b.c,a\.b.c\.f,a.a,a.b,a.b\.c\.d,a.f.g\.h,a.f.g\.h\.k,a.f.h.l\.m\.n\.o\.p
2+
a,4,5,6,1,2,32,3,5,qrstuv
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a\.a,a\.b.c\.d,a\.b.c,a\.b.c\.f,a.a,a.b,a.b\.c\.d,a.f.g\.h,a.f.g\.h\.k,a.f.h.l\.m\.n\.o\.p,c
2+
a,4,5,6,1,2,32,3,5,qrstuv,"[{""d.e"":103,""f"":2},{""d.e"":105,""f"":5}]"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a\.a,a\.b.c\.d,a\.b.c,a\.b.c\.f,a.a,a.b,a.b\.c\.d,a.f.g\.h,a.f.g\.h\.k,a.f.h.l\.m\.n\.o\.p,c.d\.e,c.f
2+
a,4,5,6,1,2,32,3,5,qrstuv,103,2
3+
a,4,5,6,1,2,32,3,5,qrstuv,105,5

test/data/json/nestedDotKeys.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"a.a": "a",
4+
"a.b": {
5+
"c.d": 4,
6+
"c": 5,
7+
"c.f": 6
8+
},
9+
"a": {
10+
"a": 1,
11+
"b": 2,
12+
"b.c.d": 32,
13+
"f": {
14+
"g.h": 3,
15+
"g.h.k": 5,
16+
"h": {
17+
"l.m.n.o.p": "qrstuv"
18+
}
19+
}
20+
}
21+
}
22+
]

0 commit comments

Comments
 (0)