mbostock / rw

Now stdin and stdout are files.
Other
117 stars 6 forks source link

read-file.js:21:35 error? #8

Closed badosa closed 7 years ago

badosa commented 7 years ago

On Node v6.4.0 (Mac OSX) with d3-dsv, running

> curl "http://api.statbank.dk/v1/data/LIVS2/JSONSTAT?lang=en&TILFREDS=*&SCORE=*" | json2csv > test.csv

/usr/local/lib/node_modules/d3-dsv/build/d3-dsv.js:26
  rows.forEach(function(row) {
       ^

TypeError: rows.forEach is not a function
    at inferColumns (/usr/local/lib/node_modules/d3-dsv/build/d3-dsv.js:26:8)
    at Object.format (/usr/local/lib/node_modules/d3-dsv/build/d3-dsv.js:113:36)
    at /usr/local/lib/node_modules/d3-dsv/bin/json2dsv:28:54
    at Socket.<anonymous> (/usr/local/lib/node_modules/d3-dsv/node_modules/rw/lib/rw/read-file.js:21:35)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:975:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
mbostock commented 7 years ago

Here are some hints to help you debug.

  1. What does curl "http://api.statbank.dk/v1/data/LIVS2/JSONSTAT?lang=en&TILFREDS=*&SCORE=*" return? Is it an object or an array?

  2. What does json2csv takes as input? Is it an object or an array? (Hint: it uses d3.csvParse under the hood.)

  3. Where did the error occur? Is this an error in rw or d3-dsv?

If you want more help, please use Stack Overflow. Although I make an effort to assist everyone that asks, I am not always available to provide help promptly or directly. Stack Overflow provides a better collaborative forum for self-help: tens of thousands of D3- (and JavaScript-)related questions have already been asked there, and some answered questions may be relevant to you.

When asking for help, please include a link to a live example that demonstrates the issue, preferably on bl.ocks.org. It is often impossible to debug from code snippets alone. Isolate the issue and reduce your code as much as possible before asking for help. The less code you post, the easier it is for someone to debug, and the more likely you are to get a helpful response.

If you have a question about D3’s behavior and want to discuss it with other users, also consider the d3-js Google Group or joining the d3-js Slack.

Thank you! 🤗

badosa commented 7 years ago
  1. What does curl "http://api.statbank.dk/v1/data/LIVS2/JSONSTAT?lang=en&TILFREDS=*&SCORE=*" return? Is it an object or an array?

An object, but this was only partially relevant because the issue was not about json2csv being able to process the input but about rw being able to read it on the first place. At least that was my first impression after trying several inputs and modules based on rw. But I'll research further.

  1. What does json2csv takes as input? Is it an object or an array? (Hint: it uses d3.csvParse under the hood.)

Replied in 1. (I'm perfectly familiar with d3-dsv, thank you: I've published many examples based on it.)

  1. Where did the error occur? Is this an error in rw or d3-dsv?

I'm posting it here, so you can figure out that my guess was that this was an rw issue.