I am new on ruby, i am not faimilar with the code block…
How can I get all the key element in an json format text?
text= "[{ "name" : "car", "status": "good"},
{ "name" : "bus", "status": "bad"},{ "name" : "taxi", "status": "soso"}]"
From the text, it is a string with json like format,
how can i extract the name value only and input into an array
desired output ==>
[car, bus, taxi]
You need to parse the JSON data first:
Then you can simply collect the items:
If you don’t have name for every item and you want a default value instead:
If you want just skip them: