Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndjson and json array format #284

Closed
Keyang opened this issue Oct 19, 2018 · 3 comments
Closed

ndjson and json array format #284

Keyang opened this issue Oct 19, 2018 · 3 comments
Assignees
Milestone

Comments

@Keyang
Copy link
Owner

Keyang commented Oct 19, 2018

Thank you for your package.
I just started using it today.
I have a question about my probable misunderstanding of use stream.

Here are my 2 different experiments with the file:

------ test.csv
nom,insee,pop
Marseille,13055,800000
Paris,75000,25000000

1st test:
const csv=require('csvtojson')
csv({includeColumns:/(nom|insee)/, colParser:{"insee":"string"},
checkType:true})
.fromFile("test.csv")
.then(jsonObj => fs.writeFile("result.json", JSON.stringify(jsonObj),
(err) => {if (err) return console.log(err);}))

------ result.json
[{"nom":"Marseille","insee":"13055"},{"nom":"Paris","insee":"75000"}]

Correct answer as expected.

but

2nd test:
const csv=require('csvtojson')
const fs = require('fs');
fs.createReadStream("test.csv")
.pipe(csv({includeColumns:/(nom|insee)/,
colParser:{"insee":"string"}, checkType:true}))
.pipe(fs.createWriteStream("result.json"));

------ result.json
{"nom":"Marseille","insee":"13055"}
{"nom":"Paris","insee":"75000"}

Not quite correct
(missing comma between objects and overall sqare brackets)
I don't see where I am wrong in second piece of code.

Thank you for your assistance.
Best regards
Robert.

@Keyang Keyang self-assigned this Oct 19, 2018
@hashinteractive
Copy link

I'm getting the same results when I try to pipe fs.createReadStream to fs.createWriteStream

@Keyang
Copy link
Owner Author

Keyang commented Jun 26, 2019

developed with downstreamFormat parameters

@Keyang Keyang closed this as completed Jun 26, 2019
@AllanOricil
Copy link

@Keyang I can't make it work. What Im doing wrong
#467

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants