diff --git a/docs/lib/dev.md b/docs/lib/dev.md index 5db03fe..4e174c7 100644 --- a/docs/lib/dev.md +++ b/docs/lib/dev.md @@ -73,6 +73,21 @@ REMOTE Remote host --- +## ppretty-json + +Pretty prints JSON string. Can accept JSON from stdin also so it's great to use in a pipe. + +**Usage** + +``` +ppretty-json [JSON] + +Params: +JSON JSON string. If not supplied read from stdin. +``` + +--- + ## ppretty-php Pretty prints a serialized PHP object/array. Can accept serial string from stdin also so it's great to use in a pipe. diff --git a/lib/dev.sh b/lib/dev.sh index 16e3964..94c47fa 100644 --- a/lib/dev.sh +++ b/lib/dev.sh @@ -57,6 +57,18 @@ echo "\n"; EOF } +## Pretty print JSON +## +## @param $1 JSON string +########################### +ppretty-json() { + local serial="${1:-}" + [[ -z "${serial}" ]] && read -r serial + + echo + jq '.' <<<"${serial}" +} + ## Bump version (for semantic versioning) ## ## @param $1 Current version