Skip to content

Instantly share code, notes, and snippets.

@joeyklee
Created April 14, 2020 17:36
Show Gist options
  • Save joeyklee/3ca73027a6f15235ae578ea2b5d9bbaa to your computer and use it in GitHub Desktop.
Save joeyklee/3ca73027a6f15235ae578ea2b5d9bbaa to your computer and use it in GitHub Desktop.
Node.js script to filter json data based on some attribute
/**
Must be run in node.js
you can run this script by opening up your terminal:
```
$ node nyc-dog-dataset-filterby-birthyear.js
```
**/
const fs = require('fs');
// read in your data - this assumes you have the json data for the dog licensing dataset in the same folder
const data = require('./NYC_Dog_Licensing_Dataset.json');
// let data2016 = data.filter(item => Number(item['Extract Year']) === 2016 );
let birth2016 = data.filter(item => Number(item['AnimalBirthMonth']) === 2016 );
console.log('all dogs', data.length);
console.log('dogs born in 2016:', birth2016.length);
// write out your data to a file
fs.writeFileSync('NYC_Dog_Licensing_Dataset__birth-2016.json', JSON.stringify(birth2016))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment