forms_to_json

0.0.10 • Public • Published

Form to json

A lightweight module (without Jquery) for serializing html forms into a JSON object. In addition, it supports serialization of input fields with files in base64.

npm i forms_to_json -S

Serialize Form

Example serialize HTML form.

import FormToJSON from 'forms_to_json';

const $form = document.querySelector('form');

const json = new FormToJSON($form).parse();
console.log(json);
/*
{
  "author": "12334",
  "year": "1900",
  "isGoldCollection": "yes",
  "type": "v2",
  "hero": [
    "spider-man",
    "batman"
  ]
}
*/

Serialize Form with Files

Files converting to base64.

Example serialize HTML form with files.

import FormToJSON from 'forms_to_json';

const $form = document.querySelector('form');

new FormToJSON($form).parseWithFiles().then((json) => {
  console.log(json);
  /*
  {
    "author": "War and Peace",
    "files": [
      "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABEwAAAJkCAYAAAALLrTbAA...."
      "data:image/png;base64,QLbZMHkY7t0kaPHi3z5s2T0qVLO2wr07p1a8mUKZO21mNf...."
    ]
  }
  */
}).catch(err => {
  console.log(err);
});

Package Sidebar

Install

npm i forms_to_json

Weekly Downloads

2

Version

0.0.10

License

ISC

Unpacked Size

13 kB

Total Files

6

Last publish

Collaborators

  • dm-kamaev