Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

posting JSON vs traditional form encoded data as the data format for submitting a form

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?

  1. Is using form encoded format (the traditional way) the better option or is it using JSON as the payload the way to go? What are some of the pros and cons you have encountered?
  2. Are web applications using JSON as the data format for submitting forms?
  3. We currently do not have any integration with mobile apps etc so is it worth doing JSON over traditional form fields approach?

Thanks for your time.

like image 202
voicestreams Avatar asked Nov 24 '12 13:11

voicestreams


2 Answers

1. Is using form fields the better option or is it using JSON the way to go?

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.

2. Are web applications using JSON for submitting forms?

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.

3. We currently do not have any integration with mobile apps etc so is it worth doing JSON over traditional form fields approach?

Again, the browser compatibility and users' bandwidth play a major role. If people have good browsers, go for it.

My suggestion:

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. :)

like image 54
Praveen Kumar Purushothaman Avatar answered Sep 18 '22 11:09

Praveen Kumar Purushothaman


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.

like image 23
Levi Botelho Avatar answered Sep 20 '22 11:09

Levi Botelho