Skip to content

Instantly share code, notes, and snippets.

@bitdivine
Created August 10, 2018 12:17
Show Gist options
  • Save bitdivine/27a313cea5fdd26ea5464d25fe7cb379 to your computer and use it in GitHub Desktop.
Save bitdivine/27a313cea5fdd26ea5464d25fe7cb379 to your computer and use it in GitHub Desktop.
Strip comments from JSON
#!/usr/bin/env node
const RECIPE = process.argv[2] || process.env.RECIPE || '/dev/stdin'
const doubleslash=/^(("([^"\\]|\\.)*"|([^\/]|\/[^\/]))*).*/gm
const multiline=/(("([^"\\]|\\.)*"|[^\/"]|\/[^*])*)\/[*]([^*]|[*][^\/])*[*]\//g
var x,y;
for ([x,y]=[require("fs").readFileSync(RECIPE,{encoding:"utf8"}).replace(doubleslash,"$1"), ""]; x.length != y.length; [x,y]=[x.replace(multiline,"$1"),x] );
console.log(JSON.stringify(JSON.parse(x), null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment