0

I want to convert json into a javascript object but i am unable to do so,since i am new.

{"campaigns":{"campDetails":[{"campaign_id":"1012","campaign_name":"RP - Axe Sample (Submit)"}]}}

into

"columns": [
            { "data": {} },
            { "data": "hr.position" },
            { "data": "contact.0" },
            { "data": "contact.1" },
            { "data": "hr.start_date" },
            { "data": "hr.salary" }
        ]

javascript object format the above is the javasctipt object to another another json. Just avoid the data I needed to know how you parse example

    "columns" : [{data:campaigndetails{ _:campaigns }}]

etc is want the out put be like

columns:[
{data:1012}.
{data:RP - Axe Sample (Submit)}
]

but i dont really know the parameters

vignesh s
  • 59
  • 6
  • The two objects have nothing in common. How do you get from one to the other? Converting a JSON **string** to a javascript **Object** is a simple as `JSON.parse(string)`. – RobG Dec 25 '14 at 05:00

2 Answers2

0

Check out http://api.jquery.com/jquery.parsejson/ - That has a good API for your task. Else, check Converting a string to JSON object - Somewhat similar to your problem.

Community
  • 1
  • 1
Vikas
  • 626
  • 1
  • 10
  • 22
0

You can use eval to convert any string into json

var str = {"campaigns":{"campDetails":[{"campaign_id":"1012","campaign_name":"RP - Axe Sample (Submit)"}]}};
var obj = eval(str);
razahassank
  • 195
  • 8