Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the key Values in a JSON array in ruby?

Tags:

json

ruby

I have the following JSON-Structure:

{ "A" : "1", "B" : "2", "RandomOtherName" : "54738" }

How can I extract the key values ("A", "B", "RandomOtherName",...) in ruby (Preferably in to an array)?

like image 851
BadJoke Avatar asked Sep 24 '15 11:09

BadJoke


1 Answers

require 'json'
data = '{ "A" : "1", "B" : "2", "RandomOtherName" : "54738" }'
JSON.parse(data).keys # => ["A", "B", "RandomOtherName"]
like image 188
ndnenkov Avatar answered Sep 29 '22 08:09

ndnenkov