jQuery JSON Cookie Plugin

Storing native JavaScript objects within cookies: JSON Cookie. Randy Morey, 25.August.2008

Storing complex data inside cookies can be hard. Using ad-hoc encoding makes it harder, especially when other developers need to work on your project. Using an ad-hoc encoding scheme is bad for these reasons:

  1. Parsing strings is an ugly business
  2. Other developers may not understand your encoding scheme
  3. You may not understand your encoding scheme (when coming back to it months from now)
  4. There's an easy way to store native JavaScript objects within cookies: JSON Cookie

How It Works

JSON Cookie stores native JavaScript objects within cookies. It works by serializing objects into JSON strings and storing them with jQuery Cookie. When read back in, it retrieves the cookie via jQuery Cookie and deserializes the object with JSON. Try out the demo below.

Try the Demo