Skip to content

Instantly share code, notes, and snippets.

@mattConn
Created March 13, 2017 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattConn/24495231c944786e52b530200a41b966 to your computer and use it in GitHub Desktop.
Save mattConn/24495231c944786e52b530200a41b966 to your computer and use it in GitHub Desktop.
Loop over an array in JSON file with Node. Hypothetical file here is "data.json", with an array named "array" located immediately within the object (not nested).
var fs = require('fs'),
util = require('util'),
exec = require('child_process').exec,
json = JSON.parse(fs.readFileSync('data.json'));
function puts(error, stdout, stderr){console.log(stdout, stderr)}
for (var i in json.array){
exec('echo '+json.array[i], puts);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment