If you have text with some lines having JSON output and some not, this jq shortcut can help you parse and format the JSON lines, helping make the output way more readable.

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

Since this is a handful I’ve defined it as an alias in my shell config like so:

alias parsejson="jq -R -r '. as \$line | try fromjson catch \$line'"

Sample usage:

$ printf "non-json content \n {\"example\": \"json\"}" | parsejson

Output:

non-json content
{
  "example": "json"
}