title: Append a new object to an array in a JSON file
body: <p>How do I add an additional object to an existing JSON file which is an array of objects?</p>
  <p>Here's my JS code:</p>
  <pre class="lang-js prettyprint-override"><code>const fs = require(&quot;fs&quot;);
  
  let Human = { 
      Name: &quot;John&quot;,
      age: 20,
  
  };
  
  Human = JSON.stringify(Human, null, 2)
  
  fs.appendFile('users.json', Human, error);
  
  function error(err) {
      console.log(&quot;1&quot;);
  }
  </code></pre>
  <p>This gives the output:</p>
  <pre><code>[
      {
        &quot;Name&quot;: &quot;John&quot;,
        &quot;age&quot;: 20,
      },
      
      {
        &quot;Name&quot;: &quot;John&quot;,
        &quot;age&quot;: 20,
      }
  ]{
    &quot;Name&quot;: &quot;John&quot;,
    &quot;age&quot;: 20,
  
  }
  </code></pre>
  <p>But I need:</p>
  <pre><code>[
      {
        &quot;Name&quot;: &quot;John&quot;,
        &quot;age&quot;: 20,
      },
      
      {
        &quot;Name&quot;: &quot;John&quot;,
        &quot;age&quot;: 20,
      },
      {
        &quot;Name&quot;: &quot;John&quot;,
        &quot;age&quot;: 20,
  
      }
  ]
  </code></pre>
  <p>How to make it write to the array correctly?</p>