I am looking to append to a JSON array in ruby. The JSON array looks like this:
{"data" : [{"name":"Chris","long":10,"lat":19}, {"name":"Scott","long":9,"lat":18}]}
I want to be able to append another object to this array e.g
{"name":"John","long":20,"lat":45}
How can I do this?
require 'json'
rb_hash = JSON.parse('{"data" : [{"name":"Chris","long":10,"lat":19}, {"name":"Scott","long":9,"lat":18}]}');
rb_hash["data"] << { name: "John", long: 20, lat: 45 }
rb_hash.to_json