6

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)?

ndnenkov
  • 35,425
  • 9
  • 72
  • 104
BadJoke
  • 147
  • 1
  • 1
  • 10

1 Answers1

13
require 'json'
data = '{ "A" : "1", "B" : "2", "RandomOtherName" : "54738" }'
JSON.parse(data).keys # => ["A", "B", "RandomOtherName"]
ndnenkov
  • 35,425
  • 9
  • 72
  • 104