Generate Nested JSON From Form Data - parseJsonFromForm

File Size: 8.55 KB
Views Total: 2804
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Generate Nested JSON From Form Data - parseJsonFromForm

A simple form to JSON jQuery plugin that generates nested JSON objects from your form data, compared to flat JSON arrays using serializeArray() jQuery method.

See Also:

How to use it:

1. Load the parseJsonFromForm script after jQuery.

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/dist/parseJsonFromForm.js"></script>

2. Convert form data into a flat JSON array using serializeArray() jQuery method

<form id="example">
  <label>First Name</label>
  <input type="email" name="first-name" value="jQuery">
  <label>Last Name</label>
  <input name="last-name" value="script">
json = jQuery('#example').serializeArray();

3. Convert form data into a nested JSON object using the parseJsonFromForm function.

json = parseJsonFromForm(jQuery('#example').serializeArray());

This awesome jQuery plugin is developed by SauliusTheBlack. For more Advanced Usages, please check the demo page or visit the official website.