title: How to pretty print a JSON inside a string with jq?
body: <p>I'm writing a more complex transformation with jq, and one of the things I'd like to do is to have a pretty printed JSON inside a string. For example:</p>
  
  <pre><code>echo '{"foo": "bar"}' | jq '{json: {other: .} | tostring}'
  </code></pre>
  
  <p>gives</p>
  
  <pre><code>{
    "json": "{\"other\":{\"foo\":\"bar\"}}"
  }
  </code></pre>
  
  <p>while I'd like to get:</p>
  
  <pre><code>{
    "json": "{\n  \"other\": {\n    \"foo\": \"bar\"\n  }\n}"
  }
  </code></pre>
  
  <p>I have also tried <code>tojson</code> and <code>@json</code>, but they give the same result as <code>tostring</code>. Is it possible to do with jq or do I have to resort to some other trickery? Note that I need to have multiple such string with formatted JSON in the output, not just one like in the example.</p>