Skip to content

Instantly share code, notes, and snippets.

@eeroan
Last active March 22, 2021 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eeroan/1aaa29cb7f0cbd756007a29a0f396e9b to your computer and use it in GitHub Desktop.
Save eeroan/1aaa29cb7f0cbd756007a29a0f396e9b to your computer and use it in GitHub Desktop.
Json formatter
#!/usr/bin/env node
const chunks = []
process.stdin
.on('data', chunk => chunks.push(chunk))
.on('end', () => console.dir(eval('(' + JSON.stringify(JSON.parse(chunks.join(''))) + ')' + process.argv.slice(2).join(' ')), { colors: true, depth: null }))
# Example: echo '{"foo": [{"bar":[2],"baz":[1,2,3]}]}'| ./format_json.js .foo[0].baz
# results: [ 1, 2, 3 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment