Skip to content

Instantly share code, notes, and snippets.

@CatTail
Created December 5, 2016 05:51
Show Gist options
  • Save CatTail/fc172a7fe6f300528665e279592c6500 to your computer and use it in GitHub Desktop.
Save CatTail/fc172a7fe6f300528665e279592c6500 to your computer and use it in GitHub Desktop.
Pretty print stdin json data, even it contains comment or other misc javascript syntax
#! /usr/bin/env node
const chunks = []
process.stdin.setEncoding('utf8')
process.stdin.on('readable', () => {
const chunk = process.stdin.read()
if (chunk) {
chunks.push(chunk)
}
})
process.stdin.on('end', () => {
const input = chunks.join('')
eval('var __data__ = ' + input)
console.log(JSON.stringify(__data__, null, ' '))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment