Skip to content

Instantly share code, notes, and snippets.

@botic
Created April 27, 2016 13:37
Show Gist options
  • Select an option

  • Save botic/ac5642fed0375fba283bdb168d2c2e21 to your computer and use it in GitHub Desktop.

Select an option

Save botic/ac5642fed0375fba283bdb168d2c2e21 to your computer and use it in GitHub Desktop.
RingoJS JSON Parser / Optimizer
const fs = require("fs");
fs.list(".").filter(function(file) {
return (file.indexOf(".json") > 0)
}).map(function(file) {
return {
path: file,
content: fs.read(file)
};
}).map(function(vinyl) {
try {
return JSON.parse(vinyl.content);
} catch (e) {
console.log("eval() fallback for " + vinyl.path);
eval("var x = " + vinyl.content + ";");
return x;
}
}).map(function(obj) {
return obj.someArray.map(function(item) { return item.link; });
}).forEach(function(obj) {
console.log(JSON.stringify(obj, null, 2));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment