0

I have json object like this

[
      {
        "name": "first_name",
        "value": "sssssssssssssssssss"
      },{
        "name": "email",
        "value": "[email protected]"
      }, {
        "name": "address",
        "value": "ssssssssssssssssssss"
      }, {
        "name": "PhoneNumber",
        "value": "12342123321"
      }     
    ]

This data is coming on form subbmission

But i want json data as

{
    "formProperties": {
        "table": "users",
        "mode": "insert",
        "method":"post",
        "action":"urlhere",
        "user":"admin"
  },
    "formValues": [
      {
        "name": "first_name",
        "value": "sssssssssssssssssss"
      },{
        "name": "email",
        "value": "[email protected]"
      }, {
        "name": "address",
        "value": "ssssssssssssssssssss"
      }, {
        "name": "PhoneNumber",
        "value": "12342123321"
      }     
    ]
}

How to reconstruct JSON object. please help me friends I was strucked with this problem.

Thanks in advance

1
  • Try JSON.parse and then construct the object by yourself. Commented Jul 7, 2015 at 9:25

1 Answer 1

2

Assume the JSON as string is saved in the variable called json you can use the following code:

var newObject = {
    "formProperties": {
        "table": "users",
        "mode": "insert",
        "method":"post",
        "action":"urlhere",
        "user":"admin"
    },
    "formValues": JSON.parse(json)
};

var newJson = JSON.stringify(newObject);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.