Created
January 2, 2024 21:44
-
-
Save juampynr/6488e2e1d5e1fe310ab59a19dab388af to your computer and use it in GitHub Desktop.
Prettify JSON string in command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo '{"a":"b"}' | jq -R -r '. as $line | try fromjson catch $line' | |
# Prints | |
# { | |
# "a": "b" | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is useful to format logs locally that use JSON. For example, in a Go application with zaplog logging you would do:
To format log entries containing JSON in a way that is human readable.