0

I have a below String in Ruby. is there any way by which i can convert this string into JSON

{
    drawer: {
        stations: {
            tv: {
                header: "TV Channels",
                logos: {
                    one: "www1",
                    two: "www2",
                    three: "www3"
                }
            }
        }
    }
}

Ideally there should be double quotes before and after the terms( like "drawer" instead of drawer). But the data returned from server is in the above format.

I am trying to use the JSON library to parse the string.

Dheeraj Tyagi
  • 31
  • 1
  • 7
  • This question has already been answered http://stackoverflow.com/questions/5410682/parsing-a-json-string-in-ruby/5410710#5410710 – JunaidKirkire Oct 23 '13 at 12:04
  • Yes i have referred this question. My question is little bit different , because the string which i am using is not a proper valid JSON. I wanted to check if there is a way by which we convert string to valid string for JSON conversion .. – Dheeraj Tyagi Oct 23 '13 at 12:18
  • What kind of format is this and where does the string come from? – Stefan Oct 23 '13 at 13:16
  • possible duplicate of [Parsing JSON without quoted keys](http://stackoverflow.com/questions/2060356/parsing-json-without-quoted-keys) – Max Oct 23 '13 at 15:51

1 Answers1

1
require 'json'

'something'.to_json #=>  "\"something\""
Bala
  • 11,068
  • 19
  • 67
  • 120