dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Other
1.92k stars 165 forks source link

Modify nested array and retain all top-level properties in piped output #113

Open jcready opened 7 years ago

jcready commented 7 years ago

Is it possible to use these new header/footer events to take JSON data like in #93 and pipe it to a write stream such that we can modify each object in the records array but also include the rest of the top-level properties in the final output piped to the write stream?

dominictarr commented 7 years ago

sure, I guess you could make a json transform stream which handled those specially somehow.

jcready commented 7 years ago

@dominictarr could you possibly provide a simple example of how to do something like this? I essentially just want to be able to mutate part of the stream inline. The only thing I seem to be able to do is have it get and make changes to each item in the records array, but then the output is just the records array. I cannot figure out how to make changes to each item in the records array and output the entire top-level structure of the input while including the mutations I made to the records array.