Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
jQuery cookie plugin for storing/retrieving JSON
branch: master

Merge pull request #1 from dragthor/master

jquery 1.5.2, 1.6, and 1.6.1 added for unit testing.  Chrome unit testing gotcha.

jQuery JSON Cookie

Cookies are the most widely available form of persistent client-side storage. Unfortunately there's no built-in support for storing structured data inside of one. That's where the jsoncookie plugin comes in; this plugin allows you to store any data that can be represented via JSON. This means that you can store objects, arrays, strings, numbers, and booleans and get the data back exactly as you expect. (Standard cookie size limitations of 4K still exist)


$.cookie( string key, mixed value [, hash options ] )

Stores a value for a given key.

  • key: Identifier for the value being stored.
  • value: The value to store. The value can be anything that can be serialized as JSON.
  • [options]: A set of key/value pairs that relate to settings for storing the value (see Options section below).


$.cookie( string key )

Gets a stored value based on the key.


Gets a hash of all stored values.


  • expires Duration in milliseconds that the cookie should exist.
  • domain Limit which pages can access the cookie based on the (sub)domain. Defaults to the current domain.
  • path Limit which pages can access the cookie based on the path. Defaulst to the current path.
  • secure Boolean. Whether to limit the cookie to only be sent over secure connections.

This plugin requires the JSON object to exist. For support in older browsers, you'll need to include json2.js.

For more information on cookies, see the MDN documentation.

Chrome doesn't support cookies for local files unless you start it with the --enable-file-cookies flag.

Something went wrong with that request. Please try again.