0

I'm trying to simulate a json response by attaching it to a variable.

myjson =    {'link':{
      'href':'erwerweirwierwe',
      'rel':'self'
   },
   'plan':{
      'shortName':'Chrome',
      'shortKey':'MASTERFULL',
      'type':'chain',
      'enabled':true,
      'link':{
         'href':'something',
         'rel':'self'
      },
      'key':'MASTERFULL',
      'name':'teserere'
   }

when i try to parse the above, i get an error:

parsedJson = JSON.parse(myjson)

do i need to format the raw json before reading it this way?

1
  • It is difficult to tell whether you have a problem in Ruby or JSON, or both. It doesn't compile as Ruby. Could you add your error message to the question? Commented Aug 10, 2013 at 7:59

1 Answer 1

2

You have to use double quotes, not single quotes.

You can validate your json using this web service.

Also, in your example, you're missing the last closing brace.

The following JSON validates:

{
"link": {
    "href": "erwerweirwierwe",
    "rel": "self"
},
"plan": {
    "shortName": "Chrome",
    "shortKey": "MASTERFULL",
    "type": "chain",
    "enabled": true,
    "link": {
        "href": "something",
        "rel": "self"
    },
    "key": "MASTERFULL",
    "name": "teserere"
}
}
Sign up to request clarification or add additional context in comments.

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.