Skip to content

Instantly share code, notes, and snippets.

@juampynr
Created January 2, 2024 21:44
Show Gist options
  • Save juampynr/6488e2e1d5e1fe310ab59a19dab388af to your computer and use it in GitHub Desktop.
Save juampynr/6488e2e1d5e1fe310ab59a19dab388af to your computer and use it in GitHub Desktop.
Prettify JSON string in command line
echo '{"a":"b"}' | jq -R -r '. as $line | try fromjson catch $line'
# Prints
# {
# "a": "b"
# }
@juampynr
Copy link
Author

juampynr commented Jan 2, 2024

This is useful to format logs locally that use JSON. For example, in a Go application with zaplog logging you would do:

make run | jq -R -r '. as $line | try fromjson catch $line'

To format log entries containing JSON in a way that is human readable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment