first time posting here. Having trouble getting into a JSON, and I could use some active.
The data that I need is at this level:
restaurant["menu"][0]["children"][0]["name"]
restaurant["menu"][0]["children"][0]["id"]
I want an array of "id"s based on "name"s.
This is the method that I'm working with:
def find_burgers(rest)
array = []
rest["menu"].each do |section|
section["children"].each do |innersection|
innersection["name"].downcase.split.include?("burger")
array.push(innersection["id"])
end
end
return array
end
As you can imagine, I'm getting back an array of every "id", not just the "id"s for burgers. I've tried many combinations of .map and .keep_if.
Thanks for reading.
EDIT: This is one menu item:
{
"children" => [
[ 0] {
"availability" => [
[0] 0
],
"children" => [
[0] {
"children" => [
[0] {
"availability" => [
[0] 0
],
"descrip" => "",
"id" => "50559491",
"is_orderable" => "1",
"name" => "Single",
"price" => "0.00"
},
[1] {
"availability" => [
[0] 0
],
"descrip" => "",
"id" => "50559492",
"is_orderable" => "1",
"name" => "Double",
"price" => "2.25"
}
],
"descrip" => "What Size Would You Like?",
"free_child_select" => "0",
"id" => "50559490",
"is_orderable" => "0",
"max_child_select" => "1",
"max_free_child_select" => "0",
"min_child_select" => "1",
"name" => "Milk Burger Size"
},
[1] {
"children" => [
[0] {
"availability" => [
[0] 0
],
"descrip" => "",
"id" => "50559494",
"is_orderable" => "1",
"name" => "Bacon",
"price" => "2.00"
}
],
"descrip" => "Add",
"free_child_select" => "0",
"id" => "50559493",
"is_orderable" => "0",
"max_child_select" => "1",
"max_free_child_select" => "0",
"min_child_select" => "0",
"name" => "Burgr Ad Bacon Optn"
}
],
"descrip" => "American cheese, lettuce, tomato and Milk Sauce",
"id" => "50559489",
"is_orderable" => "1",
"name" => "Milk Burger",
"price" => "4.25"
},