<?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/"
	xmlns:series="http://organizeseries.com/"
	>

<channel>
	<title>SitePen Blog &#187; dojo/json</title>
	<atom:link href="http://www.sitepen.com/blog/tag/dojojson/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepen.com/blog</link>
	<description>SitePen Services and notes about Dojo, Persevere, CometD, JavaScript, and the Web</description>
	<lastBuildDate>Wed, 15 May 2013 22:02:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>Native JSON Parsing in Dojo</title>
		<link>http://www.sitepen.com/blog/2012/01/05/native-json-parsing-in-dojo/</link>
		<comments>http://www.sitepen.com/blog/2012/01/05/native-json-parsing-in-dojo/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 15:05:38 +0000</pubDate>
		<dc:creator>Kris Zyp</dc:creator>
				<category><![CDATA[Dojo]]></category>
		<category><![CDATA[dojo/json]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=2259</guid>
		<description><![CDATA[<p>Dojo 1.7 introduces a new JSON module available at dojo/json. This differs from the legacy dojo.fromJson and dojo.toJson in that it is based on the new native JSON API in the JavaScript language (introduced in EcmaScript 5). It also delegates to the native JSON parser and serializer when they are available, providing the fastest possible [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<p>Dojo 1.7 introduces a new JSON module available at <code>dojo/json</code>. This differs from the legacy <code>dojo.fromJson</code> and <code>dojo.toJson</code> in that it is based on the new native JSON API in the JavaScript language (introduced in EcmaScript 5). It also delegates to the native JSON parser and serializer when they are available, providing the fastest possible execution for any given browser.</p>
<p><span id="more-2259"></span></p>
<p>Using the new API is very easy, and should be familiar if you have used json.org&#8217;s library or the browser native library. We get the JSON object from the &#8220;dojo/json&#8221; module and then can use the parse and stringify methods. For example, to parse JSON:</p>
<pre lang="javascript">define(["dojo/json"], function(JSON){
  var jsonStr = '{"name": "value"}';
  var object = JSON.parse(jsonStr);
  object.name -&gt; "value";
});</pre>
<p>Again, note that this will use the native parsing facilities of the browser/platform if they are available, otherwise they will use the library implementation.</p>
<p>To reverse the process and serialize an object to JSON:</p>
<pre lang="javascript">define(["dojo/json"], function(JSON){
  var object = {"name": "value"};
  var jsonStr = JSON.stringify(object);
  jsonStr -&gt; '{"name": "value"}'
});</pre>
<h3>Date Serialization</h3>
<p>The new JSON module now properly serializes dates. While previously, dojo.fromJson <a href="http://bugs.dojotoolkit.org/ticket/5726">incorrectly serialized dates as &#8220;{}&#8221;</a>, serialization now conforms to native date serialization. Dates are serialized to the standard ISO format in UTC.</p>
<pre lang="javascript">JSON.stringify({now:new Date()}) -&gt; "{"now":"2011-06-13T19:02:19.650Z"}"</pre>
<h3>Native Performance</h3>
<h3>Staying Light</h3>
<p>The new JSON module uses <code>has()</code> branching to determine whether or not to use the native JSON capability or not. This is not only a solid feature-detection based approach, but it means when you leverage <a href="http://www.sitepen.com/blog/?p=2203">browser-specific builds</a>, the module is only a few bytes for modern browsers, particularly valuable for mobile applications.</p>
<p>The legacy <code>dojo.fromJson</code> and <code>dojo.toJson</code> will still be available in Dojo base, but it is recommended that you use <code>parse</code> and <code>stringify</code> functions from <code>dojo/json</code> now for better performance and standards conformance.</p>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/01/05/native-json-parsing-in-dojo/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
