{"id":13459153,"url":"https://github.com/marioizquierdo/jquery.serializeJSON","last_synced_at":"2025-03-24T16:31:22.762Z","repository":{"id":4340883,"uuid":"5476727","full_name":"marioizquierdo/jquery.serializeJSON","owner":"marioizquierdo","description":"Serialize an HTML Form to a JavaScript Object, supporting nested attributes and arrays.","archived":false,"fork":false,"pushed_at":"2024-03-21T00:51:12.000Z","size":643,"stargazers_count":1713,"open_issues_count":9,"forks_count":430,"subscribers_count":60,"default_branch":"master","last_synced_at":"2025-03-19T10:18:53.318Z","etag":null,"topics":["javascript","jquery","nested-keys","parsed-values","serializejson","unchecked-checkboxes"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marioizquierdo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-08-20T03:35:18.000Z","updated_at":"2025-03-17T00:55:45.000Z","dependencies_parsed_at":"2024-06-18T11:23:09.449Z","dependency_job_id":"03a8b1cd-ad8f-4e5f-bd05-c82bae7cc8d4","html_url":"https://github.com/marioizquierdo/jquery.serializeJSON","commit_stats":{"total_commits":188,"total_committers":19,"mean_commits":9.894736842105264,"dds":0.5106382978723405,"last_synced_commit":"54b151140878253ab1a2a1f5c6a40e0e56d63af7"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marioizquierdo%2Fjquery.serializeJSON","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marioizquierdo%2Fjquery.serializeJSON/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marioizquierdo%2Fjquery.serializeJSON/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marioizquierdo%2Fjquery.serializeJSON/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marioizquierdo","download_url":"https://codeload.github.com/marioizquierdo/jquery.serializeJSON/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245308584,"owners_count":20594273,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","jquery","nested-keys","parsed-values","serializejson","unchecked-checkboxes"],"created_at":"2024-07-31T09:01:06.709Z","updated_at":"2025-03-24T16:31:22.473Z","avatar_url":"https://github.com/marioizquierdo.png","language":"JavaScript","readme":"jquery.serializeJSON\n====================\n\nAdds the method `.serializeJSON()` to [jQuery](http://jquery.com/) to serializes a form into a JavaScript Object. Supports the same format for nested parameters that is used in Ruby on Rails.\n\nInstall\n-------\n\nInstall with [bower](http://bower.io/) `bower install jquery.serializeJSON`, or [npm](https://www.npmjs.com/) `npm install jquery-serializejson`, or just download the [jquery.serializejson.js](https://raw.githubusercontent.com/marioizquierdo/jquery.serializeJSON/master/jquery.serializejson.js) script.\n\nAnd make sure it is included after jQuery, for example:\n```html\n\u003cscript type=\"text/javascript\" src=\"jquery.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"jquery.serializejson.js\"\u003e\u003c/script\u003e\n```\n\nUsage Example\n-------------\n\nHTML form:\n```html\n\u003cform\u003e\n  \u003cinput type=\"text\" name=\"title\" value=\"Dune\"/\u003e\n  \u003cinput type=\"text\" name=\"author[name]\" value=\"Frank Herbert\"/\u003e\n  \u003cinput type=\"text\" name=\"author[period]\" value=\"1945–1986\"/\u003e\n\u003c/form\u003e\n```\n\nJavaScript:\n```javascript\n$('form').serializeJSON();\n\n// returns =\u003e\n{\n  title: \"Dune\",\n  author: {\n    name: \"Frank Herbert\",\n    period: \"1945–1986\"\n  }\n}\n```\n\nNested attributes and arrays can be specified by naming fields with the syntax: `name=\"attr[nested][nested]\"`.\n\nHTML form:\n```html\n\u003cform id=\"my-profile\"\u003e\n  \u003c!-- simple attribute --\u003e\n  \u003cinput type=\"text\" name=\"name\" value=\"Mario\" /\u003e\n\n  \u003c!-- nested attributes --\u003e\n  \u003cinput type=\"text\" name=\"address[city]\"         value=\"San Francisco\" /\u003e\n  \u003cinput type=\"text\" name=\"address[state][name]\"  value=\"California\" /\u003e\n  \u003cinput type=\"text\" name=\"address[state][abbr]\"  value=\"CA\" /\u003e\n\n  \u003c!-- array --\u003e\n  \u003cinput type=\"text\" name=\"jobbies[]\"             value=\"code\" /\u003e\n  \u003cinput type=\"text\" name=\"jobbies[]\"             value=\"climbing\" /\u003e\n\n  \u003c!-- nested arrays, textareas, checkboxes ... --\u003e\n  \u003ctextarea              name=\"projects[0][name]\"\u003eserializeJSON\u003c/textarea\u003e\n  \u003ctextarea              name=\"projects[0][language]\"\u003ejavascript\u003c/textarea\u003e\n  \u003cinput type=\"hidden\"   name=\"projects[0][popular]\" value=\"0\" /\u003e\n  \u003cinput type=\"checkbox\" name=\"projects[0][popular]\" value=\"1\" checked /\u003e\n\n  \u003ctextarea              name=\"projects[1][name]\"\u003etinytest.js\u003c/textarea\u003e\n  \u003ctextarea              name=\"projects[1][language]\"\u003ejavascript\u003c/textarea\u003e\n  \u003cinput type=\"hidden\"   name=\"projects[1][popular]\" value=\"0\" /\u003e\n  \u003cinput type=\"checkbox\" name=\"projects[1][popular]\" value=\"1\"/\u003e\n\n  \u003c!-- select --\u003e\n  \u003cselect name=\"selectOne\"\u003e\n    \u003coption value=\"paper\"\u003ePaper\u003c/option\u003e\n    \u003coption value=\"rock\" selected\u003eRock\u003c/option\u003e\n    \u003coption value=\"scissors\"\u003eScissors\u003c/option\u003e\n  \u003c/select\u003e\n\n  \u003c!-- select multiple options, just name it as an array[] --\u003e\n  \u003cselect multiple name=\"selectMultiple[]\"\u003e\n    \u003coption value=\"red\"  selected\u003eRed\u003c/option\u003e\n    \u003coption value=\"blue\" selected\u003eBlue\u003c/option\u003e\n    \u003coption value=\"yellow\"\u003eYellow\u003c/option\u003e\n\t\u003c/select\u003e\n\u003c/form\u003e\n\n```\n\nJavaScript:\n\n```javascript\n$('#my-profile').serializeJSON();\n\n// returns =\u003e\n{\n  fullName: \"Mario\",\n\n  address: {\n    city: \"San Francisco\",\n    state: {\n      name: \"California\",\n      abbr: \"CA\"\n    }\n  },\n\n  jobbies: [\"code\", \"climbing\"],\n\n  projects: {\n    '0': { name: \"serializeJSON\", language: \"javascript\", popular: \"1\" },\n    '1': { name: \"tinytest.js\",   language: \"javascript\", popular: \"0\" }\n  },\n\n  selectOne: \"rock\",\n  selectMultiple: [\"red\", \"blue\"]\n}\n```\n\nThe `serializeJSON` function returns a JavaScript object, not a JSON String. The plugin should probably have been called `serializeObject` or similar, but that plugin name was already taken.\n\nTo convert into a JSON String, use the `JSON.stringify` method, that is available on all major [new browsers](http://caniuse.com/json).\nIf you need to support very old browsers, just include the [json2.js](https://github.com/douglascrockford/JSON-js) polyfill (as described on [stackoverfow](http://stackoverflow.com/questions/191881/serializing-to-json-in-jquery)).\n\n```javascript\nvar obj = $('form').serializeJSON();\nvar jsonString = JSON.stringify(obj);\n```\n\nThe plugin serializes the same inputs supported by [.serializeArray()](https://api.jquery.com/serializeArray/), following the standard W3C rules for [successful controls](http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2). In particular, the included elements **cannot be disabled** and must contain a **name attribute**. No submit button value is serialized since the form was not submitted using a button. And data from file select elements is not serialized.\n\n\nParse values with :types\n------------------------\n\nFields values are `:string` by default. But can be parsed with types by appending a `:type` suffix to the field name:\n\n```html\n\u003cform\u003e\n  \u003cinput type=\"text\" name=\"default\"          value=\":string is default\"/\u003e\n  \u003cinput type=\"text\" name=\"text:string\"      value=\"some text string\"/\u003e\n  \u003cinput type=\"text\" name=\"excluded:skip\"    value=\"ignored field because of type :skip\"/\u003e\n\n  \u003cinput type=\"text\" name=\"numbers[1]:number\"        value=\"1\"/\u003e\n  \u003cinput type=\"text\" name=\"numbers[1.1]:number\"      value=\"1.1\"/\u003e\n  \u003cinput type=\"text\" name=\"numbers[other]:number\"    value=\"other\"/\u003e\n\n  \u003cinput type=\"text\" name=\"bools[true]:boolean\"      value=\"true\"/\u003e\n  \u003cinput type=\"text\" name=\"bools[false]:boolean\"     value=\"false\"/\u003e\n  \u003cinput type=\"text\" name=\"bools[0]:boolean\"         value=\"0\"/\u003e\n\n  \u003cinput type=\"text\" name=\"nulls[null]:null\"         value=\"null\"/\u003e\n  \u003cinput type=\"text\" name=\"nulls[other]:null\"        value=\"other\"/\u003e\n\n  \u003cinput type=\"text\" name=\"arrays[empty]:array\"         value=\"[]\"/\u003e\n  \u003cinput type=\"text\" name=\"arrays[list]:array\"          value=\"[1, 2, 3]\"/\u003e\n\n  \u003cinput type=\"text\" name=\"objects[empty]:object\"       value=\"{}\"/\u003e\n  \u003cinput type=\"text\" name=\"objects[dict]:object\"        value='{\"my\": \"stuff\"}'/\u003e\n\u003c/form\u003e\n```\n\n```javascript\n$('form').serializeJSON();\n\n// returns =\u003e\n{\n  \"default\": \":string is the default\",\n  \"text\": \"some text string\",\n  // excluded:skip is ignored in the output\n\n  \"numbers\": {\n    \"1\": 1,\n    \"1.1\": 1.1,\n    \"other\": NaN, // \u003c-- \"other\" is parsed as NaN\n  },\n  \"bools\": {\n    \"true\": true,\n    \"false\": false,\n    \"0\": false, // \u003c-- \"false\", \"null\", \"undefined\", \"\", \"0\" are parsed as false\n  },\n  \"nulls\": {\n    \"null\": null, // \u003c-- \"false\", \"null\", \"undefined\", \"\", \"0\"  are parsed as null\n    \"other\": \"other\" // \u003c-- if not null, the type is a string\n  },\n  \"arrays\": { // \u003c-- uses JSON.parse\n    \"empty\": [],\n    \"not empty\": [1,2,3]\n  },\n  \"objects\": { // \u003c-- uses JSON.parse\n    \"empty\": {},\n    \"not empty\": {\"my\": \"stuff\"}\n  }\n}\n```\n\nTypes can also be specified with the attribute `data-value-type`, instead of adding the `:type` suffix in the field name:\n\n```html\n\u003cform\u003e\n  \u003cinput type=\"text\" name=\"anumb\"   data-value-type=\"number\"  value=\"1\"/\u003e\n  \u003cinput type=\"text\" name=\"abool\"   data-value-type=\"boolean\" value=\"true\"/\u003e\n  \u003cinput type=\"text\" name=\"anull\"   data-value-type=\"null\"    value=\"null\"/\u003e\n  \u003cinput type=\"text\" name=\"anarray\" data-value-type=\"array\"   value=\"[1, 2, 3]\"/\u003e\n\u003c/form\u003e\n```\n\nIf your field names contain colons (e.g. `name=\"article[my::key][active]\"`) the last part after the colon will be confused as an invalid type. One way to avoid that is to explicitly append the type `:string` (e.g. `name=\"article[my::key][active]:string\"`), or to use the attribute `data-value-type=\"string\"`. Data attributes have precedence over `:type` name suffixes. It is also possible to disable parsing `:type` suffixes with the option `{ disableColonTypes: true }`.\n\n\n### Custom Types\n\nUse the `customTypes` option to provide your own parsing functions. The parsing functions receive the input name as a string, and the DOM elment of the serialized input.\n\n```html\n\u003cform\u003e\n  \u003cinput type=\"text\" name=\"scary:alwaysBoo\" value=\"not boo\"/\u003e\n  \u003cinput type=\"text\" name=\"str:string\"      value=\"str\"/\u003e\n  \u003cinput type=\"text\" name=\"five:number\"     value=\"5\"/\u003e\n\u003c/form\u003e\n```\n\n```javascript\n$('form').serializeJSON({\n  customTypes: {\n    alwaysBoo: (strVal, el) =\u003e {\n      // strVal: is the input value as a string\n      // el: is the dom element. $(el) would be the jQuery element\n      return \"boo\"; // value returned in the serialization of this type\n    },\n  }\n});\n\n// returns =\u003e\n{\n  \"scary\": \"boo\",  // \u003c-- parsed with custom type \"alwaysBoo\"\n  \"str\": \"str\",\n  \"five\": 5,\n}\n```\n\nThe provided `customTypes` can include one of the `detaultTypes` to override the default behavior:\n\n```javascript\n$('form').serializeJSON({\n  customTypes: {\n    alwaysBoo: (strVal) =\u003e { return \"boo\"; },\n    string: (strVal) =\u003e { return strVal + \"-OVERDRIVE\"; },\n  }\n});\n\n// returns =\u003e\n{\n  \"scary\": \"boo\",         // \u003c-- parsed with custom type \"alwaysBoo\"\n  \"str\": \"str-OVERDRIVE\", // \u003c-- parsed with custom override \"string\"\n  \"five\": 5,              // \u003c-- parsed with default type \"number\"\n}\n```\n\nDefault types used by the plugin are defined in `$.serializeJSON.defaultOptions.defaultTypes`.\n\n\nOptions\n-------\n\nWith no options, `.serializeJSON()` returns the same as a regular HTML form submission when serialized as Rack/Rails params. In particular:\n\n  * Values are **strings** (unless appending a `:type` to the input name)\n  * Unchecked checkboxes are ignored (as defined in the W3C rules for [successful controls](http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2)).\n  * Disabled elements are ignored (W3C rules)\n  * Keys (input names) are always **strings** (nested params are objects by default)\n\nAvailable options:\n\n  * **checkboxUncheckedValue: string**, return this value on checkboxes that are not checked. Without this option, they would be ignored. For example: `{checkboxUncheckedValue: \"\"}` returns an empty string. If the field has a `:type`, the returned value will be properly parsed; for example if the field type is `:boolean`, it returns `false` instead of an empty string.\n  * **useIntKeysAsArrayIndex: true**, when using integers as keys (i.e. `\u003cinput name=\"foods[0]\" value=\"banana\"\u003e`), serialize as an array (`{\"foods\": [\"banana\"]}`) instead of an object (`{\"foods\": {\"0\": \"banana\"}`).\n  * **skipFalsyValuesForFields: []**, skip given fields (by name) with falsy values. You can use `data-skip-falsy=\"true\"` input attribute as well. Falsy values are determined after converting to a given type, note that `\"0\"` as `:string` (default) is still truthy, but `0` as `:number` is falsy.\n  * **skipFalsyValuesForTypes: []**, skip given fields (by :type) with falsy values (i.e. `skipFalsyValuesForTypes: [\"string\", \"number\"]` would skip `\"\"` for `:string` fields, and `0` for `:number` fields).\n  * **customTypes: {}**, define your own `:type` functions. Defined as an object like `{ type: function(value){...} }`. For example: `{customTypes: {nullable: function(str){ return str || null; }}`. Custom types extend defaultTypes.\n  * **defaultTypes: {defaults}**, contains the orignal type functions `string`, `number`, `boolean`, `null`, `array`, `object` and `skip`.\n  * **defaultType: \"string\"**, fields that have no `:type` suffix and no `data-value-type` attribute are parsed with the `string` type function by default, but it could be changed to use a different type function instead.\n  * **disableColonTypes: true**, do not parse input names as types, allowing field names to use colons. If this option is used, types can still be specified with the `data-value-type` attribute. For example `\u003cinput name=\"foo::bar\" value=\"1\" data-value-type=\"number\"\u003e` will be parsed as a number.\n\nMore details about these options in the sections below.\n\n## Include unchecked checkboxes\n\nOne of the most confusing details when serializing a form is the input type checkbox, because it includes the value if checked, but nothing if unchecked.\n\nTo deal with this, a common practice in HTML forms is to use hidden fields for the \"unchecked\" values:\n\n```html\n\u003c!-- Only one booleanAttr will be serialized, being \"true\" or \"false\" depending if the checkbox is selected or not --\u003e\n\u003cinput type=\"hidden\"   name=\"booleanAttr\" value=\"false\" /\u003e\n\u003cinput type=\"checkbox\" name=\"booleanAttr\" value=\"true\" /\u003e\n```\n\nThis solution is somehow verbose, but ensures progressive enhancement, it works even when JavaScript is disabled.\n\nBut, to make things easier, `serializeJSON` includes the option `checkboxUncheckedValue` and the possibility to add the attribute `data-unchecked-value` to the checkboxes:\n\n```html\n\u003cform\u003e\n  \u003cinput type=\"checkbox\" name=\"check1\" value=\"true\" checked/\u003e\n  \u003cinput type=\"checkbox\" name=\"check2\" value=\"true\"/\u003e\n  \u003cinput type=\"checkbox\" name=\"check3\" value=\"true\"/\u003e\n\u003c/form\u003e\n```\n\nSerializes like this by default:\n\n```javascript\n$('form').serializeJSON();\n\n// returns =\u003e\n{check1: 'true'} // check2 and check3 are ignored\n```\n\nTo include all checkboxes, use the `checkboxUncheckedValue` option:\n\n```javascript\n$('form').serializeJSON({checkboxUncheckedValue: \"false\"});\n\n// returns =\u003e\n{check1: \"true\", check2: \"false\", check3: \"false\"}\n```\n\nThe `data-unchecked-value` HTML attribute can be used to targed specific values per field:\n\n```html\n\u003cform id=\"checkboxes\"\u003e\n  \u003cinput type=\"checkbox\" name=\"checked[b]:boolean\"   value=\"true\" data-unchecked-value=\"false\" checked/\u003e\n  \u003cinput type=\"checkbox\" name=\"checked[numb]\"        value=\"1\"    data-unchecked-value=\"0\"     checked/\u003e\n  \u003cinput type=\"checkbox\" name=\"checked[cool]\"        value=\"YUP\"                               checked/\u003e\n\n  \u003cinput type=\"checkbox\" name=\"unchecked[b]:boolean\" value=\"true\" data-unchecked-value=\"false\" /\u003e\n  \u003cinput type=\"checkbox\" name=\"unchecked[numb]\"      value=\"1\"    data-unchecked-value=\"0\" /\u003e\n  \u003cinput type=\"checkbox\" name=\"unchecked[cool]\"      value=\"YUP\" /\u003e \u003c!-- No unchecked value specified --\u003e\n\u003c/form\u003e\n```\n\n```javascript\n$('form#checkboxes').serializeJSON(); // No option is needed if the data attribute is used\n\n// returns =\u003e\n{\n  'checked': {\n    'b':     true,\n    'numb':  '1',\n    'cool':  'YUP'\n  },\n  'unchecked': {\n    'bool': false,\n    'bin':  '0'\n    // 'cool' is not included, because it doesn't use data-unchecked-value\n  }\n}\n```\n\nYou can use both the option `checkboxUncheckedValue` and the attribute `data-unchecked-value` at the same time, in which case the option is used as default value (the data attribute has precedence).\n\n```javascript\n$('form#checkboxes').serializeJSON({checkboxUncheckedValue: 'NOPE'});\n\n// returns =\u003e\n{\n  'checked': {\n    'b':     true,\n    'numb':  '1',\n    'cool':  'YUP'\n  },\n  'unchecked': {\n    'bool': false,   // value from data-unchecked-value attribute, and parsed with type \"boolean\"\n    'bin':  '0',     // value from data-unchecked-value attribute\n    'cool': 'NOPE'   // value from checkboxUncheckedValue option\n  }\n}\n```\n\n## Ignore Empty Form Fields\n\nYou can use the option `.serializeJSON({skipFalsyValuesForTypes: [\"string\"]})`, which ignores any string field with an empty value (default type is :string, and empty strings are falsy).\n\nAnother option, since `serializeJSON()` is called on a jQuery object, is to just use the proper jQuery selector to skip empty values (see [Issue #28](https://github.com/marioizquierdo/jquery.serializeJSON/issues/28) for more info):\n\n```javascript\n// Select only imputs that have a non-empty value\n$('form :input[value!=\"\"]').serializeJSON();\n\n// Or filter them from the form\nobj = $('form').find('input').not('[value=\"\"]').serializeJSON();\n\n// For more complicated filtering, you can use a function\nobj = $form.find(':input').filter(function () {\n          return $.trim(this.value).length \u003e 0\n      }).serializeJSON();\n```\n\n\n## Ignore Fields With Falsy Values\n\nWhen using :types, you can also skip falsy values (`false, \"\", 0, null, undefined, NaN`) by using the option `skipFalsyValuesForFields: [\"fullName\", \"address[city]\"]` or `skipFalsyValuesForTypes: [\"string\", \"null\"]`.\n\nOr setting a data attribute `data-skip-falsy=\"true\"` on the inputs that should be ignored. Note that `data-skip-falsy` is aware of field :types, so it knows how to skip a non-empty input like this `\u003cinput name=\"foo\" value=\"0\" data-value-type=\"number\" data-skip-falsy=\"true\"\u003e` (Note that `\"0\"` as a string is not falsy, but `0` as number is falsy)).\n\n\n## Use integer keys as array indexes\n\nBy default, all serialized keys are **strings**, this includes keys that look like numbers like this:\n\n```html\n\u003cform\u003e\n  \u003cinput type=\"text\" name=\"arr[0]\" value=\"foo\"/\u003e\n  \u003cinput type=\"text\" name=\"arr[1]\" value=\"var\"/\u003e\n  \u003cinput type=\"text\" name=\"arr[5]\" value=\"inn\"/\u003e\n\u003c/form\u003e\n```\n\n```javascript\n$('form').serializeJSON();\n\n// arr is an object =\u003e\n{'arr': {'0': 'foo', '1': 'var', '5': 'inn' }}\n```\n\nWhich is how Rack [parse_nested_query](http://codefol.io/posts/How-Does-Rack-Parse-Query-Params-With-parse-nested-query) behaves. Remember that serializeJSON input name format is fully compatible with Rails parameters, that are parsed using this Rack method.\n\nUse the option `useIntKeysAsArrayIndex` to interpret integers as array indexes:\n\n```javascript\n$('form').serializeJSON({useIntKeysAsArrayIndex: true});\n\n// arr is an array =\u003e\n{'arr': ['foo', 'var', undefined, undefined, undefined, 'inn']}\n```\n\n**Note**: this was the default behavior of serializeJSON before version 2. You can use this option for backwards compatibility.\n\n\n## Option Defaults\n\nAll options defaults are defined in `$.serializeJSON.defaultOptions`. You can just modify it to avoid setting the option on every call to `serializeJSON`. For example:\n\n```javascript\n$.serializeJSON.defaultOptions.checkboxUncheckedValue = \"\"; // include unckecked checkboxes as empty strings\n$.serializeJSON.defaultOptions.customTypes.foo = (str) =\u003e { return str + \"-foo\"; }; // define global custom type \":foo\"\n```\n\n\nAlternatives\n------------\n\nOther plugins solve the same problem in similar ways:\n\n * https://github.com/macek/jquery-serialize-object\n * https://github.com/hongymagic/jQuery.serializeObject\n * https://github.com/danheberden/jquery-serializeForm\n * https://github.com/maxatwork/form2js (plain js, no jQuery)\n * https://github.com/serbanghita/formToObject.js (plain js, no jQuery)\n * https://gist.github.com/shiawuen/2634143 (simpler but small)\n\nNone of them did what I needed at the time `serializeJSON` was created. Factors that differentiate `serializeJSON` from the alternatives:\n\n * Simple and small code base. The minimified version is \u003c 1Kb.\n * Yet flexible enough with features like nested objects, unchecked-checkboxes and custom types.\n * Implementation follows the same rules as the jQuery method `serializeArray`, that creates a JavaScript array of objects, ready to be encoded as a JSON string. Taking into account the W3C rules for [successful controls](http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2) for better compatibility.\n * The format for the input field names is the same used by Rails (from [Rack::Utils.parse_nested_query](http://codefol.io/posts/How-Does-Rack-Parse-Query-Params-With-parse-nested-query)), that is successfully used by many backend systems and already well understood by many front end developers.\n * Exaustive test suite helps iterate on new releases and bugfixes with confidence.\n * Compatible with [bower](https://github.com/bower/bower), [zepto.js](http://zeptojs.com/) and pretty much every version of [jQuery](https://jquery.com/).\n\n\nContributions\n-------------\n\nContributions are awesome. Feature branch *pull requests* are the preferred method. Just make sure to add tests for it. To run the jasmine specs, just open `spec/spec_runner_jquery.html` in your browser.\n\nChangelog\n---------\n\nSee [CHANGELOG.md](./CHANGELOG.md)\n\nAuthor\n-------\n\nWritten and maintained by [Mario Izquierdo](https://github.com/marioizquierdo)\n","funding_links":[],"categories":["JavaScript","Web 前端"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarioizquierdo%2Fjquery.serializeJSON","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarioizquierdo%2Fjquery.serializeJSON","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarioizquierdo%2Fjquery.serializeJSON/lists"}