I implemented a JSON processor with many (but not all) of the features of jq, an open source command line json processor. Jq itself is written in C++, while this remake uses Haskell.

The parsing is based on this surprisingly short functional parsing library by Graham Hutton (also seen on Computerphile). Turns out monads are useful for something.

Usage example

It also turns out that NASA provides a free API as part of its Sentry system, which tracks objects that are currently projected to impact Earth with a certain probability some time in the future.

Let’s say we wanted to check out some of that data. If we curl the API endpoint with a GET request, we get back a huge JSON object. We can save this object to impact_data.json:

curl https://ssd-api.jpl.nasa.gov/sentry.api > impact_data.json

We can then pipe the JSON into the processor a give it a filter, such as getting the length of the data array containing the objects:

cat data.json | jq-clone '.data | length'

Right now that returns a length of 1581. What if we want to know something more complicated, like whether any of the projected cumulative impact probabilities are larger than 1%?

cat data.json | jq-clone '[.data[].ip | tonumber | . > 0.01]'

Interestingly enough that returns true, and it turns out that there are 2 objects right now that have a larger than 2% probability of impacting Earth within a couple hundred years. We can see the exact range of years during which this could occur by checking out the range field for each object:

cat data.json | jq-clone '.data[].range'

Overall this was a great way to learn functional programming while also learning about a neat tool.