Here is how to do it with Groovy script.
Create a Groovy script, let's say "pretty-print"
#!/usr/bin/env groovy
import groovy.json.JsonOutput
System.in.withReader { println JsonOutput.prettyPrint(it.readLine()) }
Make script executable:
chmod +x pretty-print
Now from the command line,
echo '{"foo": "lorem", "bar": "ipsum"}' | ./pretty-print