question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting header row from `csv` event

See original GitHub issue

Is there a way to get the header row from a csv event (without listening to json, end_parsed or record_parsed)? The following does not provide access to header row from csv event:

/**
csvStr:
a,b,c
1,2,3
4,5,6
7,8,9
*/
const csv=require('csvtojson')
csv()
.fromString(csvStr)
.on('csv',(csvRow)=>{ // this func will be called 3 times 
    console.log(csvRow) // => [1,2,3] , [4,5,6]  , [7,8,9] 
})
.on('done',()=>{
    //parsing finished 
})

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Keyangcommented, Mar 16, 2017

Considering a new header event which will be populated when header:true

1reaction
Keyangcommented, Mar 7, 2017

If your pass in noHeader:true in param, csv event will emit the header with first callback

Keyang

Sent from my iPhone

On 7 Mar 2017, at 20:02, Brandon Parise notifications@github.com wrote:

@Keyang The example above, there is no way to get the headers when in csv mode. I need the headers of the CSV file but don’t need each row mapped with them:

const csv=require(‘csvtojson’) csv() .fromString(csvStr) .on(‘header’, (headers) => {}) // headers = [col1, col2,…] .on(‘csv’,(csvRow)=>{ // this func will be called 3 times console.log(csvRow) // => [1,2,3] , [4,5,6] , [7,8,9] }) .on(‘done’,()=>{ //parsing finished }) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error getting header row from the CSV file
I am working using DataLoader 45.0.0 to migrate our current SF to FSC. When choosing the CSV file in the "Load Inserts" dialog...
Read more >
Use csv-parser to only return file headers
Emitted after the header row is parsed. The first parameter of the event callback is an Array[String] containing the header names. use .on(' ......
Read more >
How to add a header to a CSV file in Python?
Initially, create a header in the form of a list, and then add that header to the CSV file using to_csv() method. The...
Read more >
Imported CSV not using "use First Row as Headers"
Hi When I use import from CSV file in Excel (version 1808 - Build 10730.20264 - Semi annual Channel) it does not use...
Read more >
Assistance with Importing CSV with headers on row 2
We have an integration from peoplesoft where data was emailed in with attachment, in xlsx format, that had the headers on row 2, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found