Giter Site home page Giter Site logo

jsonify's Introduction

JSONify

JSONify is a minimal (less than a KB!) HTML-form to JSON to HTML-form converting plugin for jQuery. It creates JSON string from the name-and-value pair of form fields, and can perform JSON to form initialization.

Latest Release - v0.3.2

Now includes support for loading data from JSON to form, AKA "deJSONify", just like jsonify() extracts data from the form fields, dejsonify() can assign JSON data back to form fields. See usage section for more.

Usage

JSONify can be included in your webpage as follows:

<script type="text/javascript" src="js/jsonify.js"></script>

It provides two methods jsonify() and dejsonify(data) to perform Form Data to JSON and JSON to Form Data conversions.

jsonify()


This method converts form field values into standard JSON object, it can be called on any valid form element, which returns JSON string representing the form fields. Note that form fields must have name attribute in order to be included in JSON string.

Additionally, you can provide stringify parameter to method to specify whether to get JSON string or JSON object, using jsonify({ stringify:true }) (default is false).

dejsonify(data)


This method performs extact reverse operation of jsonify, call this method on any valid form element having input fields with attribute name specified, pass the parameter data, which can be a valid JSON object or string, and it will assign values of each item from data to the matching name of input fields.

Example

Include in your webpage as:

<script type="text/javascript" src="js/jsonify.js"></script>

Your form in page:

<form id="myform">
	<label>Name:</label>
	<input type="text" name="name"/>
	<label>Email</label>
	<input type="text" name="email"/>
	<label>Password</label>
	<input type="password" name="password"/>
</form>

Calling jsonify() as follows:

$("#myform").jsonify();

Returned JSON string:

{"name":"Kushal","email":"[email protected]","password":"awesome"}

Calling dejsonify() as follows:

$("#myform").dejsonify({
	"name": "Kushal",
	"email": "[email protected]",
	"password": "awesome"
});

And you'll have form items filled up with matching key names with name attribute of each field.

Issues

Feel free to submit any issue OR helping to fix an issue.

##Version Information

  • 0.1 - First Release.
  • 0.2 - Option can be provided whether to create JSON string or JSON object.
  • 0.3 - Support for JSON to form initialization added via method dejsonify.
  • 0.3.1 - Fixes incorrect value population with dejsonify when input types radio and checkbox are present in form.
  • 0.3.2 - Fix improper null check in jsonify method.

Author

Kushal Pandya

jsonify's People

Contributors

kushalpandya avatar singhananya09 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.