First you need to parse the JSON data:
require('json')
text = '[{ "name" : "car", "status": "good"}, { "name" : "bus", "status": "bad"},{ "name" : "taxi", "status": "soso"}]'
data = JSON.parse(text)
Then you can simply collect the elements:
p data.collect { |item| item['name'] }
If you do not have a name for each element and you want to use the default value:
p data.collect { |item| item.fetch('name', 'default value') }
If you want to just skip them:
p data.collect { |item| item['name'] }.compact
source
share