Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Created October 30, 2015 00:00
Show Gist options
  • Save gitfvb/0a7ea57c6910bb5bc2d2 to your computer and use it in GitHub Desktop.
Save gitfvb/0a7ea57c6910bb5bc2d2 to your computer and use it in GitHub Desktop.
use node.js to load JSON content from a url and then reformat it
//Load the request module
var request = require('request');
var content = request('<url with json content>', function (error, response, body) {
if (!error && response.statusCode == 200) {
//console.log(body); // Show the HTML for the Modulus homepage.
//console.log(util.inspect(body, {showHidden: false, depth: null})); // show the full content
// load the modules
var bbj2j = require('jsonapter');
var j2j = bbj2j.instance();
var jsonave = require('jsonave').instance;
// define the template
var template = {
dataKey: jsonave('DataGridSimpleResult.Rows[1:]'),
value: function (input) {
return {
cuEntity: input.Cells[0].DataValue,
cuFirstn: input.Cells[1].DataValue,
cuLastna: input.Cells[2].DataValue,
cuCity: input.Cells[3].DataValue
}
}
};
// reformat and output the json content
var r = j2j.run(template, JSON.parse(body));
console.log(r);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment