How to get the path for objects filtered using Pick in streamValues? #135
-
Hello, I have the following object: {
"id": "11937b58-4561-466b-8d48-ea2a519747f9",
"name": "Person XYZ",
"optionalKey1": "value1",
"optionalKey2": "value2",
"optionalKey3": {
"key": "val"
},
"bigArray": []
} My use case is to stream this JSON and retain everything except I tried the following way: const obj = {};
const pipeline = StreamChain.chain([
fs.createReadStream('sample.json'),
Pick.withParser({
filter: (stack) => {
return stack.length > 1 && stack[0] !== 'bigArray';
},
}),
StreamValues.streamValues(),
]);
pipeline.on('data', (data) => (obj[data.key] = data.value)); The data emitted does not retain the actual path of the value in the original JSON, something like Since the JSON can have optional keys too, it is not possible for me to map back a fixed set of values using the order of data emitted. I tried using // this works, but may not be as efficient as using filter?
const pipeline = StreamChain.chain([
fs.createReadStream('sample.json'),
StreamObject.withParser({
objectFilter: (asm) => {
return asm.key !== 'bigArray';
}
}),
]); I tried both approaches and here are the results. The file I'm trying this on is a 375 MB file.
So it definitely makes sense that using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
My understanding is that you want to preserve the overall shape of your objects.
Did you try to ignore the field in question? |
Beta Was this translation helpful? Give feedback.
-
@uhop Thanks a bunch, |
Beta Was this translation helpful? Give feedback.
My understanding is that you want to preserve the overall shape of your objects.
Pick
picks subobjects, so the parent shape is lost obviously. To edit a token stream preserving the shape of original objects we have three tools:Ignore
.Did you try to ignore the field in question?