1

I need help to convert a JSON like this

{ "phrase": [{ "content_type": "text", "title": "blablabla 1", "payload": "blabla", "text": "" }, { "content_type": "text", "title": "blablabla 2", "payload": "blabla", "text": "" }, { "content_type": "text", "title": "blablabla 3", "payload": "blabla", "text": "" }], "ogg": "true", "custom": "true" }

To an object used in a function as "options"(or "settings", you know) like this

function(){
  options = {
       phrase: [
                {
                    content_type: "text",
                    title: "blablabla 1",
                    payload: "blabla",
                    text: ""
                },
                {
                    content_type:"text",
                    title:"blablabla 2",
                    payload: "blabla"
                },
                {
                    content_type:"text",
                    title:"blablabla 3",
                    payload: "blabla"
                }
       ],
       ogg: true,
       custom: true
  }

  return options;
}

Is it possibile in anyway? Thank you!

Thomas Zoechling
  • 34,177
  • 3
  • 81
  • 112
Dan Di
  • 13
  • 2

1 Answers1

1

you can use this

var obj = JSON.parse(options);

It will give you object and using the dot(.) operator you can access the data inside the object

RAUSHAN KUMAR
  • 5,846
  • 4
  • 34
  • 70
  • 1
    Thank you so much. I used JSON.parse and correct a bug about double quotes around value true (value of 'ogg' and 'custom' keys) – Dan Di Feb 17 '17 at 11:36