I have a hash from a JSON object. It looks like this:
JSON = {"kind"=>"calendar#freeBusy", "timeMin"=>"2012-02-19T19:35:00.000Z", "timeMax"=>"2012-02-19T19:40:00.000Z", "calendars"=>{"[email protected]"=>{"busy"=>[{"start"=>"2012-02-19T19:35:00Z", "end"=>"2012-02-19T19:40:00Z"}]}}}
I want to check if there's any children of busy (a child of calendars).
I can access the children of calendars by JSON["calendars"]
That returns:
{"[email protected]"=>{"busy"=>[{"start"=>"2012-02-19T19:35:00Z", "end"=>"2012-02-19T19:40:00Z"}]}}
but JSON["calendars"]["busy"] (which is how I think you're meant to access child elements?) returns nil.
How do I get inside the "busy" child?
I created the hash using JSON.parse to a Faraday request.
"busy" is nested under "[email protected]" in your case, so you need to include this as well: JSON["calendars"]["[email protected]"]["busy"].If you want access this attribute for all calendars, you'll have to loop:
JSON["calendars"].each do |key, value|
# working with value["busy"]...
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With