juanjoDiaz / streamparser-json

Streaming JSON parser in Javascript for Node.js and the browser
MIT License
138 stars 11 forks source link

This is awesome 😎 👏 #16

Closed chrispahm closed 2 years ago

chrispahm commented 2 years ago

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

juanjoDiaz commented 2 years ago

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();
  };