dominictarr / JSONStream

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

Get the n th item in array #163

Open sign0 opened 6 years ago

sign0 commented 6 years ago

Hi !

Do you have a method to retrieve a specific item in an array ? Example : get the 200'042 th element from an array of 256'000 items.

[
    {"header":{...},"data":[......]},
    {"header":{...},"data":[......]},
    ......
    {"header":{...},"data":[......]}, <-- TARGET
    ...
    {"header":{...},"data":[......]},
]

Thanks

Poetro commented 6 years ago

Since JSONStream gives you a stream of items, you will have to process all, and throw away the unwanted items. Maybe keep a counter of the items processed, so you will know which ones you need to keep.

sign0 commented 6 years ago

Yes, that's already what I do. But it's very slow in my case and I wondered if it was possible to do otherwise. I will rather try with bash commands to see if it's possible.

Thanks