juanjoDiaz/streamparser-json

This is awesome ๐Ÿ˜Ž ๐Ÿ‘

Closed this issue ยท 1 comments

Thanks so much for making this library!
I was looking for a web compatible version of https://github.com/node-geojson/geojson-stream, and luckily stream-reading GeoJSON is possible using the path option.

P.S.: I made a small demo for streaming GeoJSON on Observable:
https://observablehq.com/@chrispahm/streaming-geojson

Great that it works for you.

Btw, there is no need to delete the keys from the parent as you do.
You can set the keepStack option to false and it will do it for you ๐Ÿ˜‰

Also, there is no need to check stack.length === 0 as you do. This will never be emitted because you are using the paths option.

  const jsonparser = new JSONParser({ paths: ["$.features.*"], keepStack: false });
  
  // Draw each feature in the GeoJSONs `feature` array
  jsonparser.onValue = (feature, key, parent, stack) => {
    context.beginPath();
    path(feature);
    context.stroke();
  };