Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8832

[nodejs] Filter keys from json with nodejs

$
0
0

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

// require fs libraryconstfs=require('fs');// read json from fileconstfileContent=fs.readFileSync('input.json','utf8');// parse as arrayconstjsonArray=JSON.parse(fileContent);// for each value from json array// pick the id column onlyvarresult=[]jsonArray.forEach(value=>{varobj={}obj['id']=value['id'];result.push(obj);});// convert to json string and write to filefs.writeFileSync('output.json',JSON.stringify(result));

Viewing all articles
Browse latest Browse all 8832

Trending Articles