We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug
I've installed csv-stringify via npm install.
To Reproduce
import { stringify as csvStringify } from "csv-stringify/sync"; jsonString = `{"test":["1","2"]}` jsonData = JSON.parse(jsonString); console.log(csvStringify([jsonData], { delimiter: ",", header: true }));
Additional context
I've expecting result as below.
test 1 2
But the result came as below.
test "[""1"",""2""]"
Thanks for your help!
The text was updated successfully, but these errors were encountered:
Hey @DevRockstarZ,
This is how it's done:
import { stringify as csvStringify } from "csv-stringify/sync"; const jsonString = `{"test":["1","2"],"test2":["1","2"],"test3":["1"]}` const jsonData = JSON.parse(jsonString); const headers = Object.keys(jsonData) let csvLength = 0 const csvData = [] console.log('headers',headers) for( const head of headers){ csvLength = jsonData[head].length > csvLength ? jsonData[head].length : csvLength } console.log('csvLength',csvLength) for (let i = 0; i < csvLength; i++) { console.log("Iteration:", i); const row = headers.reduce((accumulator, currentValue) => ({[currentValue]:jsonData[currentValue][i] ?? '',...accumulator}),{}) csvData.push(row) console.log('row',row) console.log('csvData',row) } console.log('final','csvData',csvData) console.log('output') console.log(csvStringify(csvData, { header: true }));
You can find more info in the docs
Sorry, something went wrong.
No branches or pull requests
Describe the bug
I've installed csv-stringify via npm install.
To Reproduce
Additional context
I've expecting result as below.
But the result came as below.
Thanks for your help!
The text was updated successfully, but these errors were encountered: