You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way I would like it to be chucked is by each element of each array. I understand that streamArray() can do this. However, I also would like to keep the key updated and not as a counter.
Desire output
classStreamObjectArraysextendsStreamBase{private_level: number;private_lastKey: string|null;staticmake(options?: StreamBase.StreamOptions){returnnewStreamObjectArrays(options);}staticwithParser(options: FilterOptions){returnwithParser(StreamObjectArrays.make,options);}constructor(options?: StreamBase.StreamOptions){super(options);this._level=2;this._lastKey=null;}_wait(chunk: any,_: BufferEncoding,callback: TransformCallback){if(chunk.name!=='startObject'){returncallback(newError('Top-level object should be an object.'));}this._transform=this._filter;returnthis._transform(chunk,_,callback);}_push(discard: boolean){if(this._assembler.stack.length===2&&this._assembler.stack[1]!==this._lastKey){this._lastKey=String(this._assembler.stack[1]);}_push(discard: boolean){if(this._assembler.stack.length===2&&this._assembler.stack[1]!==this._lastKey){this._lastKey=String(this._assembler.stack[1]);}if(this._lastKey!==null){if(this._assembler.current.length){this.push({key: this._lastKey,value: this._assembler.current.pop(),});}}}}
I had a previous version that was getting the key from _assembler.key in the same way as done in streamObject and updating the level. But I was unable to find the right way to reset the level and the key as once set to level 2 I was never able to get back the top level key from assembler anymore.
This discussion was converted from issue #174 on March 16, 2026 13:17.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm trying to create a custom streamer to parse the following type of file
{ "attr1": [ {"a": "data", "id": 1 }, {"a": "data", "id": 2 } ], "attr2": [ {"b": "data", "id": 1 }, {"b": "data", "id": 2 } ] }The way I would like it to be chucked is by each element of each array. I understand that
streamArray()can do this. However, I also would like to keep the key updated and not as a counter.Desire output
I came up with this solution
I had a previous version that was getting the key from
_assembler.keyin the same way as done in streamObject and updating the level. But I was unable to find the right way to reset the level and the key as once set to level 2 I was never able to get back the top level key from assembler anymore.I feel unsettle of using the assembler stack to retrieve the parent key. I wonder if their is not a better & cleaner solution instead
Beta Was this translation helpful? Give feedback.
All reactions