0

I'm looking for the inverse of this question in that I seek a utility that can consume a rendered (view source) HTML page/form and generate the JSON that can represent that form's posting. 1

The answer suggested http://www.jsonschema.net is close in format - JSON schema to/from JSON code - I want to paste in an HTML form and see the JSON stubbed out.

thx

Community
  • 1
  • 1
justSteve
  • 5,444
  • 19
  • 72
  • 137

1 Answers1

0

Something like this:

$fn.serializeForm = function()
{
 var o = {};
  var a = this.serializeArray();
  $.each(a, function() {
      if (o[this.name]) {
          if (!o[this.name].push) {
              o[this.name] = [o[this.name]];
          }
          o[this.name].push(this.value || '');
      } else {
          o[this.name] = this.value || '';
      }
  });

 return o;
}

Then call:

$('form').serializeForm();
jfrey
  • 44
  • 4