Skip to content
Submit forms as json
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
lib
script
test
.gitignore
LICENSE
README.md
package.json
webpack.config.js

README.md

JSONForms

An implementation of the algorithm outlined here for submitting form data as JSON. Convert any form into a structured JSON object.

Submitting this form

<form enctype='application/json'>
  <input name='places[0][city]' value='New York City'>
  <input type='number' name='places[0][population]' value='8175133'>
  <input name='places[1][city]' value='Los Angeles'>
  <input type='number' name='places[1][population]' value='3792621'>
  <input name='places[2][city]' value='Chicago'>
  <input type='number' name='places[2][population]' value='2695598'>
</form>

uploads this object

{
  "places": [
    {
      "city": "New York City",
      "population": 8175133
    },
    {
      "city": "Los Angeles",
      "population": 3792621
    },
    {
      "city": "Chicago",
      "population": 2695598
    }
  ]
}

Usage:

Include the script in your page and any form with an attribute of enctype set to 'application/json' will submit data with a json payload.

To disable json post submission

JSONForms.disable()

To enable

JSONForms.enable()

To create a JSON object of a form

JSONForms.encode(formElement)

TODO

  • Add support for file input types
  • Add support for other input elements like radios, textareas
You can’t perform that action at this time.