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