Created
April 27, 2016 13:37
-
-
Save botic/ac5642fed0375fba283bdb168d2c2e21 to your computer and use it in GitHub Desktop.
RingoJS JSON Parser / Optimizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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