Merging several paths in a single object using JSONStream.parse

169 Views Asked by At

After getting help from stackoverflow a lot, this is actually my first time asking a question, so do not hesitate to correct me if I could have done it better.

I'm trying to parse a stream which as this structure:

{
    ...
    "features":{
        ...
        "geometry": { "a": 1, "b":2...},
        "properties":{"x": "foo", "y": "bar"},
        ...
    }
    ...
}

Into objects (one for each "features") looking like this:

{
    "geometry": 
    { 
        "a": 1, 
        "b":2
        ...
    },
    "x": "foo",
    "y": "bar"
}

So grabbing the "geometry" and its depth, and the "properties". For now, my code look like this :

request(featuresUrl)
    .pipe(JSONStream.parse(['features', true, /properties|geometry/]))
    .pipe(index.defaultPipeline())
    .pipe(index.add())
    .on('finish', function() {
        console.log(`items loaded`);
        resolve();
    })

The issue is that I have two different objects that are indexed, one with the geometry, the other with the properties. I would like it to be a single object, with both merged, if possible.

What is the best solution? To change the way I parse the JSONStream? Or to insert something after the .parse that would grab both object and merge them?

0

There are 0 best solutions below