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?
This is how my Json file currently looks like
answers.json
{"visit_count":280,"employability":"employed","nationality":"Canadian","income":"5555","email":"dsfs@fsfs"}
{"visit_count":280,"employability":"employed","nationality":"Canadian","income":"5555","email":"dsfs@fsfs"}
This is how I'm storing data in my json file
if env["REQUEST_METHOD"] == "POST"
json = template_data.to_json
open('answers.json', 'a') do |file|
file.puts json
end
end
I tried this solution to merge JSON objects
data_hash = JSON.parse(File.read('answers.json'))
data_hash.gsub(/}.*?{/m, '},{')}]")
this is the error that showed up when I tried the above
`load': admin.rb:10: syntax error, unexpected tSTRING_DEND, expecting keyword_end (SyntaxError)
ta_hash.gsub(/}.*?{/m, '},{')}]")
Any help would be greatly appreciated