title: How to prettify JSON.stringify() partially?
body: <p>Users can download JSON files from our application, which I want to prettify for easier debugging than if all is in one line. However this increases the file size by nearly 40% even if the indentation is just a single tab or space.</p>
  <p>As a compromise, I want to exclude all values with e.g. the key &quot;large&quot; from prettification, like this:</p>
  <pre><code>{
   &quot;small&quot;:
   {
    &quot;a&quot;: 1,
    &quot;b&quot;: 2,
    &quot;large&quot;: {&quot;a&quot;:1,&quot;b&quot;:2,&quot;c&quot;:3,&quot;d&quot;:&quot;the \&quot;large\&quot; object should not be prettified&quot;} 
   },
    &quot;large&quot;: {&quot;a&quot;:1,&quot;b&quot;:2,&quot;c&quot;:3,&quot;d&quot;:&quot;the \&quot;large\&quot; object should not be prettified&quot;}
  }
  </code></pre>
  <p>I tried to solve this using the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify" rel="nofollow noreferrer">replacer parameter</a> of JSON.stringify:</p>
  <pre><code>JSON.stringify(data,(key,value)=&gt;key===&quot;large&quot;?JSON.stringify(data):value,'\t');
  </code></pre>
  <p>However the values for the &quot;large&quot; keys ends up escaped:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>data = 
  {
       "small":
       {
        "a": 1,
        "b": [2,3,4,5],
        "large": {"myarray":[1,2,3,4],"b":2,"c":3,"d":"the \"large\" object should not be prettified"} 
       },
        "large": {"a":1,"b":2,"c":3,"d":"the \"large\" object should not be prettified"}
      }
      
   const json =  JSON.stringify(data,(key,value)=&gt;key==="large"?JSON.stringify(data):value,'\t');
   document.getElementById("json").innerText = json;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;body&gt;
  &lt;pre id="json"&gt;
  &lt;/pre&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>How can I prevent this escaping from happening or otherwise partially prettify JSON in JavaScript?</p>