Appending to JSON array in Ruby Appending to JSON array in Ruby json json

Appending to JSON array in Ruby


First convert the JSON to a Ruby hash this way:

require 'json'rb_hash = JSON.parse('<your json>');rb_hash["data"] << { name: "John", long: 20, lat: 45 }rb_hash.to_json


If you want to append existing hash, we can do as below-

hash = {} 

I have another hash as-

sub_hash = {}

then-

hash.merge!(sub_hash) 

will work great!!!