I have a response string that looked something like this:
"[{\"id\":\"blahbla23sdlkjrwer2345\",\"name\":\"bar\"},{\"id\":\"aselrjdsfsomething\",\"name\":\"foo\"}]"
Then I used JSON.parse(response_above):
json_parse = JSON.parse(response_above)
=>[{"id"=>"blahbla23sdlkjrwer2345", "name"=>"bar"},
{"id"=>"aselrjdsfsomething", "name"=>"foo"}]
From here I only want the names and put them into an array. I figured out how to get the names but don't how to build it into a new array.
To get just "foo" or "bar" I can do this:
json_parse[0].fetch("name")
=> "bar"
json_parse[1].fetch("name")
=> "foo"
I don't how to iterate through the array to build a new array from the JSON response like:
new_array = ["foo", "bar"]
The JSON response can be dynamic, sometimes I may only have 2 elements, other times I can have 10 elements. I can't hard code a value in. I need to find a way to iterate through that array for the "name" key getting each of the values.