A Customized CSV to Json Converter CLI
Based on https://github.com/Keyang/node-csvtojson
Input csv
id,bool_data,date,
|arraycatagories|,
:arraycatagories:,
|jsonarrayemployee.catagories,
jsonemployee.name,
jsonemployee.age,
jsonemployee.number,
arrayaddress,
arrayaddress,
jsonarrayemployee.key,
jsonarrayemployee.key,
omitid
1,true,2012-02-12,a|b|c|f,"a:b:c:f",a|b|c|f,Eric,31,51234,Dunno Street,Kilkeny Road,key1,key2,2
1,false,2012-03-06,a|b|c|,"a:b:c:","a|b|c",Ted,28,51289,"21, Cambridge Road",Tormore,key3,key4,4
Output json
[{
"id": 1,
"bool_data": true,
"date": "2012-02-12",
"catagories|": ["a", "b", "c", "f"],
"catagories:": ["a", "b", "c", "f"],
"employee": {
"catagories": ["a", "b", "c", "f"],
"name": "Eric",
"age": 31,
"number": 51234,
"key": ["key1", "key2"]
},
"address": ["Dunno Street", "Kilkeny Road"]
}, {
"id": 1,
"bool_data": false,
"date": "2012-03-06",
"catagories|": ["a", "b", "c", ""],
"catagories:": ["a", "b", "c", ""],
"employee": {
"catagories": ["a", "b", "c"],
"name": "Ted",
"age": 28,
"number": 51289,
"key": ["key3", "key4"]
},
"address": ["21, Cambridge Road", "Tormore"]
}]
Added Parser Types
1. \
|array\ : parser a|b|c|d into [a,b,c,d], i.e: \
|array\catagories
2. \
|jsonarray\ : parser a|b|c|d into [a,b,c,d],i.e: \
|jsonarray\my.catagories
3. \
:array\ : parser a:b:c:d into [a,b,c,d], i.e: \
:array\catagories
4. \
:jsonarray\ : parser a:b:c:d into [a,b,c,d],i.e: \
:jsonarray\my.catagories
#usage
csv2json test.csv > converted.json
cat test.csv | csv2json > converted.json