",
6 | "contributors": [],
7 | "dependencies": { },
8 | "devDependencies": { },
9 | "main": "json2csv.js",
10 | "keywords": ["csv", "json", "parse", "convert"],
11 | "repository": {
12 | "type": "git",
13 | "url": "git://github.com/martindrapeau/csvjson-json2csv.git"
14 | },
15 | "license": "MIT"
16 | }
--------------------------------------------------------------------------------
/test-browser.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CSVJSON's json2csv Test
5 |
6 |
7 | CSVJSON's json2csv Test
8 |
9 | Test
10 | const obj = [
11 | {
12 | "album": "The White Stripes",
13 | "year": 1999,
14 | "US_peak_chart_post": "-"
15 | },
16 | {
17 | "album": "De Stijl",
18 | "year": 2000,
19 | "US_peak_chart_post": "-"
20 | },
21 | {
22 | "album": "White Blood Cells",
23 | "year": 2001,
24 | "US_peak_chart_post": 61
25 | },
26 | {
27 | "album": "Elephant",
28 | "year": 2003,
29 | "US_peak_chart_post": 6
30 | },
31 | {
32 | "album": "Get Behind Me Satan",
33 | "year": 2005,
34 | "US_peak_chart_post": 3
35 | },
36 | {
37 | "album": "Icky Thump",
38 | "year": 2007,
39 | "US_peak_chart_post": 2
40 | },
41 | {
42 | "album": "Under Great White Northern Lights",
43 | "year": 2010,
44 | "US_peak_chart_post": 11
45 | },
46 | {
47 | "album": "Live in Mississippi",
48 | "year": 2011,
49 | "US_peak_chart_post": "-"
50 | },
51 | {
52 | "album": "Live at the Gold Dollar",
53 | "year": 2012,
54 | "US_peak_chart_post": "-"
55 | },
56 | {
57 | "album": "Nine Miles from the White City",
58 | "year": 2013,
59 | "US_peak_chart_post": "-"
60 | }
61 | ];
62 |
63 | const csv = CSVJSON.json2csv(obj);
64 |
65 | Expected
66 | "album","year","US_peak_chart_post"
67 | "The White Stripes",1999,"-"
68 | "De Stijl",2000,"-"
69 | "White Blood Cells",2001,61
70 | "Elephant",2003,6
71 | "Get Behind Me Satan",2005,3
72 | "Icky Thump",2007,2
73 | "Under Great White Northern Lights",2010,11
74 | "Live in Mississippi",2011,"-"
75 | "Live at the Gold Dollar",2012,"-"
76 | "Nine Miles from the White City",2013,"-"
77 |
78 | Execution
79 |
80 |
81 | Test Result
82 |
83 |
84 |
85 |
153 |
154 |
--------------------------------------------------------------------------------
/test-node.js:
--------------------------------------------------------------------------------
1 | const json2csv = require('./json2csv.js');
2 | const obj = [
3 | {
4 | "album": "The White Stripes",
5 | "year": 1999,
6 | "US_peak_chart_post": "-"
7 | },
8 | {
9 | "album": "De Stijl",
10 | "year": 2000,
11 | "US_peak_chart_post": "-"
12 | },
13 | {
14 | "album": "White Blood Cells",
15 | "year": 2001,
16 | "US_peak_chart_post": 61
17 | },
18 | {
19 | "album": "Elephant",
20 | "year": 2003,
21 | "US_peak_chart_post": 6
22 | },
23 | {
24 | "album": "Get Behind Me Satan",
25 | "year": 2005,
26 | "US_peak_chart_post": 3
27 | },
28 | {
29 | "album": "Icky Thump",
30 | "year": 2007,
31 | "US_peak_chart_post": 2
32 | },
33 | {
34 | "album": "Under Great White Northern Lights",
35 | "year": 2010,
36 | "US_peak_chart_post": 11
37 | },
38 | {
39 | "album": "Live in Mississippi",
40 | "year": 2011,
41 | "US_peak_chart_post": "-"
42 | },
43 | {
44 | "album": "Live at the Gold Dollar",
45 | "year": 2012,
46 | "US_peak_chart_post": "-"
47 | },
48 | {
49 | "album": "Nine Miles from the White City",
50 | "year": 2013,
51 | "US_peak_chart_post": "-"
52 | }
53 | ];
54 | const csv = json2csv(obj);
55 | const expected = `"album","year","US_peak_chart_post"
56 | "The White Stripes",1999,"-"
57 | "De Stijl",2000,"-"
58 | "White Blood Cells",2001,61
59 | "Elephant",2003,6
60 | "Get Behind Me Satan",2005,3
61 | "Icky Thump",2007,2
62 | "Under Great White Northern Lights",2010,11
63 | "Live in Mississippi",2011,"-"
64 | "Live at the Gold Dollar",2012,"-"
65 | "Nine Miles from the White City",2013,"-"`;
66 | console.log('==Expected==');
67 | console.log(expected);
68 | console.log('==Execution==');
69 | console.log(csv);
70 | console.log('==Result==');
71 | if (csv === expected) {
72 | console.log('Success!');
73 | } else {
74 | console.log('Failed.');
75 | }
76 |
--------------------------------------------------------------------------------