Output from csvtojson not pure JSON
See original GitHub issueI’m trying to use this tool to convert a csv to JSON. The output i’m getting is not exactly pure “JSON”.
What I tried:
var csvToJson = require('csvtojson');
const converter = csvToJson({
ignoreEmpty: true,
});
csvToJson()
.fromFile(csvFile)
.on('json', function(jsonObj) {
console.log(jsonObj);
})
.on('done', function() {
console.log("done !");
});
And the output was something like this:
{
field1: '100051',
Membership: '100051',
gender: 'male',
}
And what i’m expecting:
{
"field1": "100051",
"Membership": "100051",
"gender": "male",
}
So i’m expecting is quotes around the object keys, which is the standard JSON. How can i achieve that ?
Thanks in advance 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
nodejs - csvtojson not giving proper json keys in output
I have written below code to convert my csv file but it is not converting into json properly. The keys in json do...
Read more >csvtojson
A tool concentrating on converting csv data to JSON with customised parser supporting. Latest version: 2.0.10, last published: 3 years ago.
Read more >How to Convert CSV to JSON file having Comma ...
A CSV is a comma-separated values file with .csv extension, which allows data to be saved in a tabular format. Here is a...
Read more >Convert CSV to JSON in a JavaScript App | by John Au-Yeung
Convert to CSV Lines. We can also get the raw CSV row one row at a time with the subscribe method and the...
Read more >Top 10 CSV JavaScript Parsing Libraries 2022
Processing CSV to JSON - Top 10 CSV JavaScript Parsing Libraries 2022 ... We cannot easily filter it in its raw form or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It is because
console.log
function you used does not print the quotes – you can try with otherJSON Object
in javascript andconsole.log
will never print the quotes.I am having the same problem. The output from
csvtojson()
cannot be parsed as JSON. The thing aboutconsole.log
is also not quite right:It seems like maybe you are equating Javascript objects with JSON? In any case, this:
will throw an error
Unexpected token o in JSON at position 1
, proving that the result is not in fact JSON.