npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

formson

v0.9.1

Published

HTML forms <-> JSON functions

Downloads

67

Readme

formson: HTML forms <-> JSON

Convert HTML forms to/from JSON. As well as obeying HTML form serialisation conventions, can update deep array/object serialisations using a bracket syntax.

Inspired by:

  • https://www.w3.org/TR/html-json-forms/
  • https://www.npmjs.com/package/@f/serialize-form

Install

Install from github:

npm install git://github.com/lentinj/formson

Usage

First, import the module:

var formson = require('formson');

Then use one of the following functions

formson.update_object(obj, form_el)

Update object obj with the current values of the HTML form form_el's elements. Anything in obj that isn't referenced in form_el will be left as-is.

formson.update_form(form_el, obj)

Update HTML form form_el with the current values in object obj. The form element names are used to extract and set relevant values from obj.

formson.form_to_object(form_el)

Shorthand for formson.update_form(form_el, {}). Returns the freshly created and updated element.

Form serialisation details

Form fields can be nested at any depth using square brackets:

<input type="text" name="cow" value="bessie" />
<input type="text" name="farm[field][cow]" value="freda" />
{
    "cow": "bessie",
    "farm": { "field": { "cow": "freda" }}
}

Arrays

Multiple form fields with the same name will be treated as an array:

<input type="text" name="cows" value="bessie" />
<input type="text" name="cows" value="freda" />
<input type="text" name="cows" value="" />
<input type="text" name="cows" value="mary" />
{
    "cows": ["bessie", "freda", "", "mary"]
}

This can be forced even with a single item by using []:

<input type="text" name="cows[]" value="bessie" />
{
    "cows": ["bessie"]
}

Individual positions can also be given:

<input type="text" name="farm[cows][0]" value="bessie" />
<input type="text" name="farm[cows][3]" value="freda" />
<input type="text" name="farm[cows][2]" value="" />
<input type="text" name="farm[cows][1]" value="mary" />
{
    "farm": { "cows": ["bessie", "mary", "", "freda"] }
}

Checkboxes

Checkboxes are true if checked:

<input type="checkbox" name="farm[cows]" checked="checked" />
<input type="checkbox" name="farm[pigs]" />
{
    "farm": { "cows": true, "pigs": false }
}

Select boxes

Select boxes return the value (or text) of selected item, or an array if multiple.

<select name="cow" multiple="multiple">
  <option selected="selected" value="daisy">Daisy (the best cow)</option>
  <option selected="selected">freda</option>
  <option>bessie</option>
</select>
{
    "cow": [ "daisy", "freda" ]
}

File input

File inputs will have a javascript File object as their value, if multiple they will have an array of File objects.

License

MIT