<?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>indiegamr &#187; JSON</title>
	<atom:link href="http://indiegamr.com/category/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://indiegamr.com</link>
	<description>apps, indie &#38; beyond</description>
	<lastBuildDate>Sun, 30 Mar 2014 14:51:19 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>MsgPack vs. JSON: Cut your client-server exchange traffic by 50% with one line of code</title>
		<link>http://indiegamr.com/cut-your-data-exchange-traffic-by-up-to-50-with-one-line-of-code-msgpack-vs-json/</link>
		<comments>http://indiegamr.com/cut-your-data-exchange-traffic-by-up-to-50-with-one-line-of-code-msgpack-vs-json/#comments</comments>
		<pubDate>Sun, 10 Jun 2012 12:00:01 +0000</pubDate>
		<dc:creator><![CDATA[olsn]]></dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[ZeroPilot]]></category>

		<guid isPermaLink="false">http://indiegamr.com/?p=72</guid>
		<description><![CDATA[As the previouse 2 articles were about optimizing performance and keeping the server cost as low as possible, this article will also cover this area and write about why I&#8217;m using MsgPack instead of JSON in ZeroPilot. In a web-app &#8230; <a href="http://indiegamr.com/cut-your-data-exchange-traffic-by-up-to-50-with-one-line-of-code-msgpack-vs-json/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>As the previouse 2 articles were about optimizing performance and keeping the server cost as low as possible, this article will also cover this area and write about why I&#8217;m using <a href="http://msgpack.org/" target="_blank">MsgPack </a>instead of <a href="http://json.org/" target="_blank">JSON </a>in <a title="ZeroPilot" href="http://indiegamr.com/zeropilot/" target="_blank">ZeroPilot</a>.</p>
<p>In a web-app there is allways data sent between the client and the server &#8211; would you believe me if I told you that after otimizing all the server-calls, bundeling them together ect. you can still save up to 40% (and some cases even 60%) of your traffic caused by client-server communication with not more than <strong>one line of code</strong>?</p>
<p><span id="more-72"></span></p>
<p>Well, the magic word is &#8220;<strong><a href="http://msgpack.org/" target="_blank">MsgPack</a></strong>&#8221; &#8211; it is a &#8216;<em>binary-based efficient object serialization library</em>&#8216;. The difference to <strong><a href="http://json.org/" target="_blank">JSON</a>&nbsp;</strong>is, that MsgPack is <strong>binary-based</strong>&nbsp;&#8211; this gives the possibility to make the exchanged data <strong>a) smaller and use less bytes</strong>, I guess we all know the advantages of that, however there is an even bigger advantage:<strong>&nbsp;b) It is faster to parse</strong> and <strong>encode</strong>, having a parser parse 40 bytes takes about twice as long as parsing 20 bytes. I know those advantages might seem marginal &#8211; however if you scale this up to a couple thousand (or even more) users you will see quite a bit of a difference there. And even if you don&#8217;t have a couple thousand users &#8211; why would you not want to take advantage of something like this? <img src="http://indiegamr.com/wp-includes/images/smilies/icon_wink.gif" alt=";-)" class="wp-smiley" /></p>
<p>To make this difference more visible i put together a small example:</p>
<div style="width: 100%; background-color: #efefef;">
<div style="width: 40%; margin-left: 5%; float: left;">
<p><strong>JSON</strong></p>
<hr />
<p>{&#8220;<span style="background-color: #cc8888; background-position: initial initial; background-repeat: initial initial;">name</span>&#8220;:&#8221;<span style="background-color: #88cc88; background-position: initial initial; background-repeat: initial initial;">John Doe</span>&#8220;,&#8221;<span style="background-color: #cccc88;">age</span>&#8220;:<span style="background-color: #88cccc;">12</span>}</p>
</div>
<div style="width: 40%; margin-left: 5%; float: left;">
<p><strong>MsgPack</strong></p>
<hr />
<p>‚¤<span style="background-color: #cc8888; background-position: initial initial; background-repeat: initial initial;">name</span>¨<span style="background-color: #88cc88; background-position: initial initial; background-repeat: initial initial;">John Doe</span>&pound;<span style="background-color: #cccc88; background-position: initial initial; background-repeat: initial initial;">age</span><span style="background-color: #88cccc; background-position: initial initial; background-repeat: initial initial;">.</span></p>
</div>
<div style="clear: both;">&nbsp;</div>
<div style="width: 40%; margin-left: 5%; float: left;">
<hr />
<p>7B 22 <span style="background-color: #cc8888; background-position: initial initial; background-repeat: initial initial;">6E 61 6D 65</span> 22 3A 22 <span style="background-color: #88cc88; background-position: initial initial; background-repeat: initial initial;">4A 6F 68 6E 20 44 6F 65</span> 22 2C 22 <span style="background-color: #cccc88; background-position: initial initial; background-repeat: initial initial;">61 67 65</span> 22 3A 20 <span style="background-color: #88cccc; background-position: initial initial; background-repeat: initial initial;">31 32</span>&nbsp;7D</p>
</div>
<div style="width: 40%; margin-left: 5%; float: left;">
<hr />
<p>82 A4 <span style="background-color: #cc8888; background-position: initial initial; background-repeat: initial initial;">6E 61 6D 65</span> A8 <span style="background-color: #88cc88; background-position: initial initial; background-repeat: initial initial;">4A 6F 68 6E 20 44 6F 65</span> A3 <span style="background-color: #cccc88; background-position: initial initial; background-repeat: initial initial;">61 67 65</span> <span style="background-color: #88cccc; background-position: initial initial; background-repeat: initial initial;">0C</span></p>
</div>
<div style="clear: both;">&nbsp;</div>
<div style="width: 40%; margin-left: 5%; float: left;"><span style="text-decoration: underline;"><span style="font-size: 20pt !important;"><strong>→ 29 bytes</strong></span></span></div>
<div style="width: 40%; margin-left: 5%; float: left;"><span style="text-decoration: underline;"><span style="font-size: 20pt;"><strong>→ 20 bytes</strong></span></span></div>
<div style="clear: both;">&nbsp;</div>
</div>
<p>As you can see, the MsgPack-encoded data is about 2/3 the size of JSON.</p>
<p>(edit: I previously had some&nbsp;unnecessary bytes in the JSON code, making the example to much in favour of MsgPack, I removed those. thx to charles leifer for noticing)</p>
<p>Additionally, the whole thing look less readable when you look at it &#8211; so as a small bonus this will probably repell some script-kiddies, who are trying to intercept your JSON- or XML-calls.</p>
<p><strong>One line of code you said?</strong></p>
<hr />
<p>That is correct, assuming that you are currently using JSON: (JavaScript-example)</p>
<p><code lang="javascript">//just exchange the encoding and decoding lines<br />
myJSONString = JSON.stringify(myObject);<br />
myObject = JSON.parse(myJSONString);<br />
//with<br />
var myByteArray = msgpack.pack(myObject);<br />
myObject = msgpack.unpack(myByteArray);</code></p>
<p>MsgPack returns Objects/Hashes or Arrays, Numbers and Strings just like JSON will do, so there is NO need to change anything further than the encoding- and decoding lines.</p>
<p><strong>Why havn&#8217;t I heared from MsgPack before?</strong></p>
<hr />
<p>As with all good things: They need time, MsgPack has first been introduced about 2 1/2 years ago I believe (at least according to their<a href="https://github.com/msgpack" target="_blank"> github-repo</a>) &#8211; it might be older, but without a github repository it is rather difficult to get noticed nowadays.</p>
<p>I can only <strong>encourage</strong> you to visit the <a href="http://msgpack.org/" target="_blank">MsgPack</a>-Site and download the implementation for your programming-language(every major language has one), even if your desired language has no official implementation, there are usually unofficial projects to be found via google or github. If you can&#8217;t find it &#8211; contribute to the community and write your own implementation and share it. <img src="http://indiegamr.com/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" /></p>
<p>Edit #1: Looking at JavaScript it is true, that parsing JSON is faster than any custom parser. However, the field of usage is more than just JavaScript, considered that the serverload is probably more to be taken into account than your clients, as it won&#8217;t really matter if your clients need 0.1ms or 2ms to decode/encode something, however on the serverside MsgPack-parsing is usually faster than JSON &#8211; in the case of Ruby, MsgPack is faster by a factor of ~5.</p>
<p>Edit #2: Since there was quite a bit of critisism here and on Hacker News, Sadayuki &#8220;<a href="https://github.com/frsyuki" target="_blank">Sada</a>&#8221; Furuhashi, the creator of MessagePack posted some thoughts on MessagePack on gist: <a href="https://gist.github.com/2908191" target="_blank">https://gist.github.com/2908191</a> clarifying a few things, thank you for that Sadayuki.</p>
]]></content:encoded>
			<wfw:commentRss>http://indiegamr.com/cut-your-data-exchange-traffic-by-up-to-50-with-one-line-of-code-msgpack-vs-json/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
	</channel>
</rss>
