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
  • 96,708
  • 25
  • 150
  • 188
steve_gallagher
  • 3,678
  • 8
  • 31
  • 50

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
  • 113,563
  • 27
  • 250
  • 306
1

JSON.parse is what you're looking for

New Alexandria
  • 6,566
  • 4
  • 53
  • 72