Skip to content

Instantly share code, notes, and snippets.

@cobusc
Created November 12, 2014 07:11
Show Gist options
  • Save cobusc/f476f27fb4a9856970dc to your computer and use it in GitHub Desktop.
Save cobusc/f476f27fb4a9856970dc to your computer and use it in GitHub Desktop.
Utility to validate, pretty-print and syntax highlight JSON data
#!/bin/bash
#
# Utility to display JSON data in a pretty-printed, syntax highlighted form.
# If the data is not valid JSON, an error will be reported.
#
# An optional filename can be specified, otherwise input is read from stdin.
#
set -o pipefail
JSON=$(cat ${1:-/dev/stdin} | python -mjson.tool)
if [ $? -eq 0 ]; then
vi -R -c "set syntax=javascript" -c "set bg=dark" - <<< "${JSON}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment