zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.72k stars 362 forks source link

Validation/skipping objects #568

Closed cyril265 closed 2 years ago

cyril265 commented 2 years ago

Is there a way to validate/skip objects? Similar to the transforms parameter but for validation. For example I am streaming JSON from an http request into a csv file:

    const parsingProcessor = asyncParser
      .fromInput(request) //Readable
      .toOutput(createWriteStream(savePath));

I tried piping the request into a "filter" but it's not straightforwarded because you need to parse the json stream.

juanjoDiaz commented 2 years ago

Hi @cyril265 ,

Can you elaborate a bit more? Would you want to skip invalid objects instead of throwing an error?

cyril265 commented 2 years ago

Hey @juanjoDiaz, thank you for responding!

Would you want to skip invalid objects instead of throwing an error?

Yeah, I would like to skip invalid objects without discarding the whole stream. Basically a callback validate where the original object is passed as parameter and a boolean is returned. The object is skipped if false is returned. But now I am thinking maybe it's better to handle this outside json2csv to avoid adding additional complexity to the library.