Skip to content

Instantly share code, notes, and snippets.

@aseigneurin
Created November 18, 2013 09:53
Show Gist options
  • Save aseigneurin/7525386 to your computer and use it in GitHub Desktop.
Save aseigneurin/7525386 to your computer and use it in GitHub Desktop.
Parse a JSON file and output a SQL script with Node.js.
var fs = require('fs');
var data = fs.readFileSync(process.argv[2], {
encoding: 'ascii'
});
var json = JSON.parse(data);
for (var list in json) {
var devices = json[list];
for (var i = 0; i < devices.length; i++) {
var device = devices[i];
if (device["uid"])
console.log("UPDATE panel.device SET hardware_id = '" + device["devid"] + "' WHERE uid = '" + device["uid"] + "' AND project = 4;");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment