title: How do I merge multiple JSON objects in one file ruby
body: <p>I'm trying to loop over JSON objects and I can't because I have two separate JSON objects in my one JSON file. How would I merge the two objects?</p>
  <p>This is how my Json file currently looks like</p>
  <h1>answers.json</h1>
  <pre><code>{&quot;visit_count&quot;:280,&quot;employability&quot;:&quot;employed&quot;,&quot;nationality&quot;:&quot;Canadian&quot;,&quot;income&quot;:&quot;5555&quot;,&quot;email&quot;:&quot;dsfs@fsfs&quot;}
  {&quot;visit_count&quot;:280,&quot;employability&quot;:&quot;employed&quot;,&quot;nationality&quot;:&quot;Canadian&quot;,&quot;income&quot;:&quot;5555&quot;,&quot;email&quot;:&quot;dsfs@fsfs&quot;}
  </code></pre>
  <p>This is how I'm storing data in my json file</p>
  <pre><code>if env[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;
        json = template_data.to_json
        open('answers.json', 'a') do |file|
          file.puts json 
     end
  end
  </code></pre>
  <p>I tried this solution to merge JSON objects</p>
  <pre><code>data_hash = JSON.parse(File.read('answers.json'))
  data_hash.gsub(/}.*?{/m, '},{')}]&quot;)
  </code></pre>
  <p>this is the error that showed up when I tried the above</p>
  <pre><code>`load': admin.rb:10: syntax error, unexpected tSTRING_DEND, expecting keyword_end (SyntaxError)
  ta_hash.gsub(/}.*?{/m, '},{')}]&quot;)
  </code></pre>
  <p>Any help would be greatly appreciated</p>