<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lalit.org &#187; json</title>
	<atom:link href="http://www.lalit.org/tag/json/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lalit.org</link>
	<description>Personal page of Lalit Patel, an engineer, entrepreneur, geek from Bhubaneswar, India.</description>
	<lastBuildDate>Thu, 03 Jun 2010 05:23:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Cookie Jar: Yummy JSON Cookies (using Prototype)</title>
		<link>http://www.lalit.org/lab/jsoncookies</link>
		<comments>http://www.lalit.org/lab/jsoncookies#comments</comments>
		<pubDate>Thu, 12 Apr 2007 07:09:16 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[lab]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=20</guid>
		<description><![CDATA[JavaScript code to store data as JSON strings in cookies. It uses prototype.js to store and retrieve JSON data from cookies.
Now we can store and retrieve JavaScript Objects, Arrays, Boolean, String, Number values using cookies, just like storing Java Objects in session on the server side.

Works with Firefox 1.5, 2.0, IE 6.0 and Opera 9.10.
Example
(Execute [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript code to store data as JSON strings in cookies. It uses <a href="http://www.prototypejs.org/" target="_blank">prototype.js</a> to store and retrieve JSON data from cookies.</p>
<p>Now we can store and retrieve JavaScript Objects, Arrays, Boolean, String, Number values using cookies, just like storing Java Objects in session on the server side.<br />
<span id="more-20"></span><br />
Works with Firefox 1.5, 2.0, IE 6.0 and Opera 9.10.</p>
<h3>Example</h3>
<p>(Execute this example)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><ol><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">jar <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> CookieJar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">expires<span style="color: #339933;">:</span><span style="color: #CC0000;">3600</span><span style="color: #339933;">,</span>   <span style="color: #006600; font-style: italic;">// seconds</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">path<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/'</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">dog <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'Jacky'</span><span style="color: #339933;">,</span> breed<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Alsatian'</span><span style="color: #339933;">,</span> age<span style="color: #339933;">:</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">jar.<span style="color: #660066;">put</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mydog'</span><span style="color: #339933;">,</span> dog<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">mydog <span style="color: #339933;">=</span> jar.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mydog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;My dog's name is &quot;</span> <span style="color: #339933;">+</span> mydog.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;He is &quot;</span> <span style="color: #339933;">+</span> mydog.<span style="color: #660066;">age</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; years old&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;He is an &quot;</span> <span style="color: #339933;">+</span> mydog.<span style="color: #660066;">breed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li></ol></pre></div></div>

<h3>Download</h3>
<p>You can view the source code <a href="http://www.lalit.org/wordpress/wp-content/uploads/2008/06/cookiejar.js">here</a>.<br />
<del datetime="2009-01-25T06:10:56+00:00">This code is released under <a href="http://creativecommons.org/licenses/by-sa/2.5/" target="_blank">CC Attribution-ShareAlike 2.5</a></del></p>
<p>This code is released under <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache Software License</a>.</p>
<h3 class="bold">API</h3>
<p><code><strong>CookieJar</strong>(options)</code><br />
Constructor. Takes in a object as options.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><ol><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">expires<span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span>  <span style="color: #006600; font-style: italic;">// time in seconds (defualt: 3600)</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">path<span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span>     <span style="color: #006600; font-style: italic;">// cookie path</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">domain<span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span>   <span style="color: #006600; font-style: italic;">// cookie domain</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">secure<span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span>    <span style="color: #006600; font-style: italic;">// secure ?</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#125;</span></div></li></ol></pre></div></div>

<p><code>boolean <strong>put</strong>(string name, mixed value)</code><br />
Puts a particular cookie in the cookie jar. The cookie is associated  with the name. Returns false if cannot add cookie (Ex: max cookie size  exceeded!). Returns true on success.</p>
<p><code>mixed <strong>get</strong>(string name)</code><br />
Gets a particular cookie from the cookie jar. Returns null if not found.</p>
<p><code>boolean <strong>remove</strong>(string name)</code><br />
Removes a particular cookie from the cookie jar. Returns true on success, false otherwise.</p>
<p><code>void <strong>empty</strong>()</code><br />
Empties the Cookie Jar.</p>
<p><code>array <strong>getKeys</strong>()</code><br />
Gets array of all the cookie names.</p>
<p><code>object <strong>getPack</strong>()</code><br />
Gets all the cookies as a single JavaScript object (Package) with name value pairs.</p>
<h3>Change Log</h3>
<p><small><strong>v 0.5</strong> (26-Jan-09)</small></p>
<ol>
<li>Changed the License to Apache Software License 2.0</li>
</ol>
<p><small><strong>v 0.4</strong> (11-Aug-07)</small></p>
<ol>
<li>Removed a extra comma in options (was breaking in IE and Opera). (Thanks Jason)</li>
<li>Removed the parameter name from the initialize function</li>
<li>Changed the way expires date was being calculated. (Thanks David)</li>
</ol>
<p><small><strong>v 0.3</strong> (22-Jun-07)</small></p>
<ol>
<li>Removed dependancy on json.js (<a href="http://web.archive.org/web/20070819092735/http://www.json.org/json.js">http://www.json.org/json.js</a>)</li>
<li><span class="code">empty()</span> function only deletes the cookies set by CookieJar. Leaves alone other cookies like <span class="code">session_id</span> etc.</li>
</ol>
<p><small><strong>v 0.2</strong> (12-Apr-07)</small></p>
<ol>
<li>Released for public use.</li>
</ol>
<h3>Related</h3>
<ul>
<li><a href="http://ajaxian.com/archives/cookiejar-json-cookies">Ajaxian review</a></li>
<li><a href="http://clientside.cnet.com/code-snippets/cookiejsonjs-a-mootools-version-of-cookiejar/" target="_blank">MooTools port</a></li>
<li><a href="http://www.jdempster.com/2007/08/11/jquery-cookiejar/" target="_blank">jQuery port</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/lab/jsoncookies/feed</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
	</channel>
</rss>
