Reputation: 607
posting JSON vs traditional form encoding as the data format for submitting data to the server from a HTML form. The HTML form is dynamic as in, the user can add new rows (for example) and fill in data. There is an argument that using form fields with an MVC framework is easier in this case since the MVC framework like Spring MVC takes care of the bindings to the form (generating id's in the dynamically generated HTML etc) and we can have an object on the controller to collect these values when the form is posted using AJAX as a form encoded content type.
I was thinking of using JSON, what are your views?
Thanks for your time.
Upvotes: 8
Views: 6761
Reputation: 140
Update. Give a look to http://www.w3.org/TR/html-json-forms/
But "Beware. This specification is no longer in active maintenance and the HTML Working Group does not intend to maintain it further.".
Upvotes: 0
Reputation: 167212
You can't compare this. What you can say is, either the traditional Submit is better or JSON way, but you need to take a choice. When submitting through JSON, you cannot send files, but it needs AJAX or similar technology to talk to the server. So browser compatibility to be checked.
The question itself is wrong. No is the answer, because most of the forms are submitted by POST
and the values are sent as serialized, which doesn't always mean JSON.
Again, the browser compatibility and users' bandwidth play a major role. If people have good browsers, go for it.
There are a set of rules and best practices available for designing web applications of all kinds. Kindly go through it and work on your project. :)
Upvotes: 9
Reputation: 700650
Do you have any specific reason to post JSON?
If not, then I would say that the default choise would be to post form-data, as that is natively supported by all browsers and all servers. You can post form-data without any client script at all, and any server implemenation handles it by default.
Upvotes: 2
Reputation: 25224
I would recommend that you stick with the standard format for the framework that you are using. In terms of performance, security and reliability the people developing your framework will generally do a much better job than you will at developing such infrastructure.
This article Normal form submission vs. JSON has a bit of a discussion on the topic of basic form submission vs JSON submission. One point which I agree with is that when you start getting into complex data structures, a structured format as opposed to a flat one can be quite advantageous. That said, as you said yourself, Spring MVC and other similar frameworks take care of the binding. For me, this is the one thing that JSON can do significantly better than standard form submission. If it is taken care of by default by the framework, stick with the default. Don't go adding complexity where it isn't necessary.
Upvotes: 3
Reputation: 75644
Is using form fields the better option or is it using JSON the way to go?
You are comparing apples with hammers. JSON is data format while form is, well, let's say, data source. You can send JSON data in HTML form fields, so this question is bit odd.
Are web applications using JSON for submitting forms?
HTML forms? No
We currently do not have any integration with mobile apps etc so is it worth doing JSON over traditional form fields approach?
Again - read about the technologies you want to use. This helps to understand what it is. Do not start implementation prior getting elementary knowledge or you end wasting your time "refactoring" your project. From scratch...
Upvotes: -2