When I run
youtube-dl -j "$youtube_url" | jq
I get a nice json output. However, when I run
json=$(youtube-dl -j "$youtube_url" | jq)
then jq prints it's usage page and after that youtube-dl fails with a broken pipe error. The json-variable is empty.
I'm guessing that jq runs before youtube-dl and since there is no data on stdin then it terminates printing the usage instructions. When jq is no longer running then there is no pipe to write to so then youtube-dl fails. This is just a guess though. I do not really understand what is going on here. Please enlighten me!