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.

Stream does not return JSON array

See original GitHub issue

Hi, first of all thank you for the great lib.

I have an issue to parse a CSV using the streaming API because it does not return a JSON array. I don’t know if it is the “normal” behavior but here an example to explain my problem (with Node v0.12):

The original CSV file:

annee;jour;date;b_1;b_2;devise;
2015029;LUNDI   ;09/03/2015;35;31;eur;
2015028;SAMEDI  ;07/03/2015;48;9;eur;

The code to parse the CSV:

var rs = require('fs').createReadStream('source.csv');
var ws = require('fs').createWriteStream('destination.json');

 rs.pipe(new Converter({ constuctResult: false, delimiter: ';', trim: true })).pipe(ws);

The result file content:

{"annee":2015029,"jour":"LUNDI","date":"09/03/2015","b_1":35,"b_2":31,"devise":"eur","":""}
{"annee":2015028,"jour":"SAMEDI","date":"07/03/2015","b_1":48,"b_2":9,"devise":"eur","":""}

I would expected to have this json object:

[
  {"annee":2015029,"jour":"LUNDI","date":"09/03/2015","b_1":35,"b_2":31,"devise":"eur","":""},
  {"annee":2015028,"jour":"SAMEDI","date":"07/03/2015","b_1":48,"b_2":9,"devise":"eur","":""}
]

It works fine if I use the end_parsed event instead, but not with the stream and the pipe API.

Thank you for your help

Note: I don’t know why by it adds me an empty field in the JSON result too

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Keyangcommented, Mar 10, 2015

Hi, I just released ver 0.3.19 which includes the toArrayString feature. Try

 rs.pipe(new Converter({ constructResult: false, delimiter: ';', trim: true,toArrayString:true })).pipe(ws);

This should do what you expect.

Regards, Keyang

0reactions
yannicklcommented, Mar 11, 2015

It works perfectly, thank you very much for your reactivity!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java 8: How to write lambda stream to work with JsonArray?
Try with IntStream. List<String> jsonObject = IntStream .range(0,jsonArray.size()) .mapToObj(i -> jsonArray.
Read more >
javax.json.JsonArray.stream java code examples - Tabnine
Returns a list view for the array. The value and the type of the elements * in the list is specified by the...
Read more >
JSONStreams (Java Application API for IBM Streams)
A JSON stream is a stream of JSON objects represented by the class com.ibm.json.java.JSONObject . When a JSON value that is an array...
Read more >
JSONArray (Apache Wink 1.2.0-incubating API)
Create a new instance of this class from the data provided from the input stream. JSONArray(InputStream is, boolean strict) Create a new instance...
Read more >
3 techniques to stream JSON in Spring WebFlux
Returning large JSON arrays from WebFlux endpoint is a challenge. Assume you have a Flux<Data> that you want to return. We have at...
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