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.

3
  • 2
    JSON.parse(your_string) Commented Sep 10, 2013 at 18:59
  • possible duplicate of How do I parse JSON with Ruby on Rails? Commented Sep 10, 2013 at 19:02
  • Your expected result is not valid Ruby. Commented Sep 11, 2013 at 1:34

2 Answers 2

3

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"}]
Sign up to request clarification or add additional context in comments.

Comments

1

JSON.parse is what you're looking for

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.