<?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>Web 3.0, 6 Bladed Razors, 7 Minute Abs &#187; JSON</title>
	<atom:link href="http://www.zachleat.com/web/tag/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zachleat.com/web</link>
	<description></description>
	<lastBuildDate>Mon, 06 Feb 2012 17:09:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Javascript Objects are NOT JSON</title>
		<link>http://www.zachleat.com/web/javascript-objects-are-not-json/</link>
		<comments>http://www.zachleat.com/web/javascript-objects-are-not-json/#comments</comments>
		<pubDate>Sat, 10 May 2008 04:47:55 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/?p=134</guid>
		<description><![CDATA[The headline should more accurately read &#8220;Javascript Objects are not necessarily JSON.&#8221; But that waters it down a bit, don&#8217;t you think? I know this has been posted a few times before, but this is not something I knew until recently, and after learning it, have noticed quite a few other people doing it wrong [...]]]></description>
			<content:encoded><![CDATA[<p><em>The headline should more accurately read &#8220;Javascript Objects are not <strong>necessarily</strong> JSON.&#8221;  But that waters it down a bit, don&#8217;t you think?</em></p>
<p>I know this has been posted a few times before, but this is not something I knew until recently, and after learning it, have noticed quite a few other people doing it wrong as well.  So, to risk adding another reverb to the echo chamber, I&#8217;ll post a link to a <a href="http://www.thefutureoftheweb.com/blog/json-is-not-just-object-notation">good explanation</a> by Jesse Skinner on the specifics of the JSON specification.</p>
<p>The main point here is that <strong>all object keys and strings in JSON must have double quotes.</strong>  I encourage you to look through the <a href="http://json.org/">train track specification</a> to verify for yourself.</p>
<p>If you try to use Captain <a href="http://www.json.org/json2.js">Crockford&#8217;s JSON Parser</a>, it won&#8217;t parse your string with single quotes or (un/single)-quoted object keys.  His parser has a nice regex checker built-in (and a walker callback to let you parse date strings into Date() objects).  It&#8217;s a good way to verify that external data, or a data source not under your control, is safe to eval and use in your own code.</p>
<p>Here are a few quick examples:</p>
<h2>Valid JSON</h2>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;myKey&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;myString&quot;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Don&#8217;t use single quotes.  Don&#8217;t use unquoted object keys.</p>
<h2>Invalid JSON</h2>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>myKey<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;myString&quot;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'myKey'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'myString'</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Credits to Jonathan Snook for the <a href="http://www.snook.ca/archives/javascript/json_is_a_subse/">initial write-up</a> and Crockford for formalizing JSON.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/javascript-objects-are-not-json/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

