0
0

More than 3 years have passed since last update.

[nodejs] Filter keys from json with nodejs

Posted at

Here is a example to filter the keys of json data.

// require fs library
const fs = require('fs');

// read json from file
const fileContent = fs.readFileSync('input.json', 'utf8');

// parse as array
const jsonArray = JSON.parse(fileContent);

// for each value from json array
// pick the id column only
var result = []
jsonArray.forEach(value => {
    var obj = {}
    obj['id'] = value['id'];
    result.push(obj);
});

// convert to json string and write to file
fs.writeFileSync('output.json', JSON.stringify(result));
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0