ServerSideCat ServerSideCat - 1 year ago 86
JSON Question

Best way to build JSON with JS

I've got questionnaire page on my website using bootstrap/jquery.
I have 2 forms: for person and for business and each of it has a lot of checkboxes, input elements and etc.
On the backend side we await a json file which we will parse after user form be completed.

What are the best practices to build a json file according to the following situation. Should i do with pure JS script in the end of page or there is a better way to do it?

Answer Source

For easy use and backward compatibility you can use
Or pick the data one by one from the inputs you have and build the object you want to send to server, at the end send it using jQuery or convert it to json and do what you want using:

var jsonStr = JSON.stringify(myObjectFromFormInputs);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download