How to parse markdown text from JSON and appending it to a file without ruining the markdown formatting?

I’m reading JSON objects with jq and appending the value of fields to another file like so:

curl $JSON| jq '.body' | tee -a page1.md

This works great, however the markdown I’m extracting from the curl command is not formatting itself in page1.md. It’s just appending, and not taking into account markdown styles such as ### which would bold text.
For example, the line below is exactly what the command above is appending during a test run… Notice the quotes at the start and end of the line. All of this is outputted onto one line, ruining the integrity of the original markdown format extracted from the curl originally.

"###test test test rn**test test **rnrn> test test test testrnrnrtest test testn"

How can I append this text for markdown to read the formatting styles? I think the quotes are causing the problem?

Asked By: andres

||

The string holding the markup is stored encoded in the JSON document. Use jq -r instead of jq. This will give you the decoded ("raw") output, without the outer quotes.

Don’t forget to double-quote your shell variables when you use them.

curl "$JSON" | jq -r '.body' >> page1.md
Answered By: roaima
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.