0

I have data like:

"[{\"workstationName\":\"Test Workstation Id 123\"},{\"workstationName\":\"Alex's Workstation\"}]"

I want it to simply be:

[{"workstationName":"Test Workstation Id 123"},{"workstationName":"Alex's Workstation"}]

I should know this. I tried a.to_ary, but no good. Any straight-forward way to process this? Thanks.

Wayne Conrad
  • 103,207
  • 26
  • 155
  • 191
steve_gallagher
  • 3,778
  • 8
  • 33
  • 51

2 Answers2

4

How is this ?

require 'json'
require 'yaml'

JSON.parse("[{\"workstationName\":\"Test Workstation Id 123\"},{\"workstationName\":\"Alex's Workstation\"}]")
# => [{"workstationName"=>"Test Workstation Id 123"},
#     {"workstationName"=>"Alex's Workstation"}]

YAML.load("[{\"workstationName\":\"Test Workstation Id 123\"},{\"workstationName\":\"Alex's Workstation\"}]")
# => [{"workstationName"=>"Test Workstation Id 123"},
#     {"workstationName"=>"Alex's Workstation"}]
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
1

JSON.parse is what you're looking for

New Alexandria
  • 6,951
  • 4
  • 57
  • 77