how to construct below json object and send it to server

chaitu chaitu
chaitu chaitu used Ask the Experts™
on
HI,

I have a form in the frond end.how to construct below json object like below and send it to server

prepareJSON={"address":{"addressId":1,"addressName":"NewYork"},"firstName":"John","hireDate":"21-Oct-2008","lastName":"Abraham","salary":"1000"}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Michel PlungjanIT Expert
Top Expert 2009

Commented:
leakim971Multitechnician
Top Expert 2014

Commented:
var addressId = $("#addressId").val();
var addressName = $("#addressName").val();
var firstName = $("#firstName").val();
var hireDate = $("#hireDate").val();
var lastName = $("#lastName").val();
var salary = $("#salary").val();

prepareJSON={};
prepareJSON["address"] = {"addressId":addressId,"addressName":addressName};
prepareJSON["firstName"] = firstName;
prepareJSON["hireDate"] = hireDate;
prepareJSON["lastName"] = lastName;
prepareJSON["salary"] = salary;

Open in new window

Multitechnician
Top Expert 2014
Commented:
$.post("path/to/getJSONFromForm", {"prepareJSON":prepareJSON}, callbackFunction);

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial