ServerSideCat ServerSideCat - 7 months ago 51
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?


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);