<?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>Witslog Wiki &#187; JSON</title>
	<atom:link href="http://witslog.com/wiki/category/technical/json/feed" rel="self" type="application/rss+xml" />
	<link>http://witslog.com/wiki</link>
	<description>Technical Log</description>
	<lastBuildDate>Fri, 14 May 2010 06:17:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>fetch the records through ajax and jquery in json format using kohana</title>
		<link>http://witslog.com/wiki/technical/php/fetch-the-records-through-ajax-and-jquery-in-json-format-using-kohana</link>
		<comments>http://witslog.com/wiki/technical/php/fetch-the-records-through-ajax-and-jquery-in-json-format-using-kohana#comments</comments>
		<pubDate>Fri, 14 May 2010 06:17:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Kohana]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>

		<guid isPermaLink="false">http://witslog.com/wiki/?p=140</guid>
		<description><![CDATA[HI All,
 After spending lot&#8217;s  of time, i got result in josn format in kohana. I want to fetch all records of last 3 minutes of comment table and it will display on my site after check is record already show on browser or not.
As...]]></description>
			<content:encoded><![CDATA[<p>HI All,</p>
<p><em><strong> After spending lot&#8217;s  of time, i got result in josn format in kohana. I want to fetch all records of last 3 minutes of comment table and it will display on my site after check is record already show on browser or not.</strong></em></p>
<p><strong>As we know kohana is MVC framework so we need to handle controller as well as model.</strong></p>
<p><strong>//Model</strong></p>
<p>In model first i write query to fetch records from database which is under a function get_last_three_minutes_comments.</p>
<p>public function get_last_three_minutes_comments($id){</p>
<p>$query = $this-&gt;db-&gt;query(&#8220;SELECT u.user_name, gs.* from comments as gs INNER JOIN users as u on gs.`user_id`=u.`user_id` WHERE DATE_SUB( now( ) , INTERVAL 3 MINUTE ) &lt; gs.speak_date and gs.group_id=$id ORDER BY id DESC&#8221;);<br />
return $query-&gt;result_array();<br />
}</p>
<p><strong>//Controller</strong></p>
<p>I call this model file from controller by write below code.</p>
<p>public function get_last_three_minutes_comments($page_id){<br />
$data =    $this-&gt;comment-&gt;get_last_three_minutes_comments($page_id); // i have already made a object in constructor for comment table.</p>
<p><strong>// As we know model return data in mixture of array and object and for json we need data only in array format. so here i manipulate data and convert into array format.</strong></p>
<p>$arr = array();<br />
$id=0;<br />
foreach($data as $id =&gt; $rec){<br />
$arr[$id] = array(&#8216;id&#8217;=&gt;$rec-&gt;id,&#8217;user_name&#8217;=&gt;$rec-&gt;user_name,&#8217;speak&#8217;=&gt;$rec-&gt;speak,&#8217;speak_time&#8217;=&gt;$rec-&gt;speak_date);<br />
$id++;<br />
}</p>
<p>//Now we change value in json format using json_encode function and return to JavaScript file by echo command.</p>
<p>echo json_encode(array(&#8216;comment_data&#8217;=&gt;$arr));<br />
}</p>
<p><strong>Javascript file</strong></p>
<p>//In jquery we use $.ajax function to get data from server by using ajax. $.ajax gets some parameter such as dataType which may be get, post, json as our requirement. I use json because i need to handle data in json format. Second parameter is url. url tell to server which page will be called. third one is success. When all server processing is completed then it return data in success which i get in mycomment variable.</p>
<p>$.ajax({<br />
dataType: &#8216;json&#8217;,<br />
url:url_main+&#8221;widgets/get_runtime_comment/&#8221;+tabid[1],<br />
success:function(mycomment){</p>
<p><strong>// In controller i make a array which name is comment_data. Now i access data of json by name of javascript variable in which holds all data then after write array name of php then after call by array index. such as call to user_name field we are below line</strong></p>
<p><strong>mycomment.comment_data[0].user_name;</strong></p>
<p><strong> mycomment is javascript variable name, comment_data is php array and user_name is index name of that array.</strong></p>
<p>len = mycomment.comment_data.length; // here i get total number of records for run a loop.<br />
i=0;<br />
while(i&lt;len){<br />
cmid = mycomment.comment_data[i].id; // here i get id of current record.<br />
comt = $(&#8216;#tabs-&#8217;+tabid[1]).children().find(&#8216;.commentbox&#8217;).find(&#8216;#&#8217;+cmid).html(); // Check whether this record is exist or not in current div.</p>
<p>//if i get blank then it will added into that particular div else ignore it.<br />
if(comt==null){<br />
dt = &#8216;&lt;div id=&#8221;&#8216;+mycomment.comment_data[i].id+&#8217;&gt;&#8217;+mycomment.comment_data[i].speak+&#8217;&lt;br&gt;By: &#8211; &#8216;+mycomment.comment_data[i].user_name+&#8217; on &#8216;+mycomment.comment_data[i].speak_time+&#8217;&lt;/div&gt;&#8217;;<br />
$(&#8216;#tabs-&#8217;+tabid[1]).children().find(&#8216;.commentbox&#8217;).find(&#8216;._group_comments&#8217;).prepend(dt);<br />
}<br />
i++;<br />
}</p>
<p>}<br />
});</p>
<p>I hope you will learn lot&#8217;s of thing from this article.</p>
]]></content:encoded>
			<wfw:commentRss>http://witslog.com/wiki/technical/php/fetch-the-records-through-ajax-and-jquery-in-json-format-using-kohana/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>JSON</title>
		<link>http://witslog.com/wiki/technical/json/json</link>
		<comments>http://witslog.com/wiki/technical/json/json#comments</comments>
		<pubDate>Sat, 06 Mar 2010 22:53:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://witslog.com/wiki/?p=13</guid>
		<description><![CDATA[JSON, short for JavaScript Object Notation, is a  lightweight computer data interchange format. It is a  text-based, human-readable format for  representing simple data structures and associative arrays (called objects).
The JSON format was originally specified in RFC 4627 by Douglas Crockford. The official...]]></description>
			<content:encoded><![CDATA[<p><strong>JSON</strong>, short for <strong>JavaScript Object Notation</strong>, is a  lightweight <a title="Computer" href="http://en.wikipedia.org/wiki/Computer">computer</a> data interchange format. It is a  text-based, <a title="Human-readable" href="http://en.wikipedia.org/wiki/Human-readable">human-readable</a> format for  representing simple <a title="Data  structure" href="http://en.wikipedia.org/wiki/Data_structure">data structures</a> and <a title="Associative  array" href="http://en.wikipedia.org/wiki/Associative_array">associative arrays</a> (called objects).</p>
<p>The JSON format was originally specified in <a href="http://tools.ietf.org/html/rfc4627">RFC 4627</a> by <a title="Douglas  Crockford" href="http://en.wikipedia.org/wiki/Douglas_Crockford">Douglas Crockford</a>. The official <a title="Internet  media type" href="http://en.wikipedia.org/wiki/Internet_media_type">Internet media type</a> for JSON is <code>application/json</code>.  The JSON filename extension is <code>.json</code>.</p>
<p>The JSON format is often used for <a title="Serialization" href="http://en.wikipedia.org/wiki/Serialization">serialization</a> and transmitting structured data over a network connection. Its main  application is in <a title="Ajax  (programming)" href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">Ajax</a> web application programming, where it serves as  an alternative to the <a title="XML" href="http://en.wikipedia.org/wiki/XML">XML</a> format.</p>
<h2>History</h2>
<p>Although JSON was based on a subset of the <a title="JavaScript" href="http://en.wikipedia.org/wiki/JavaScript">JavaScript</a> programming language (specifically, Standard <a title="Ecma  International" href="http://en.wikipedia.org/wiki/Ecma_International">ECMA</a>-262 3rd Edition—December 1999<sup id="cite_ref-0"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-0">[1]</a></sup>)  and is commonly used with that language, it is considered to be a <a title="Language-independent specification" href="http://en.wikipedia.org/wiki/Language-independent_specification">language-independent</a> data  format. Code for <a title="Parsing" href="http://en.wikipedia.org/wiki/Parsing">parsing</a> and generating JSON data is readily  available for a large variety of <a title="Programming languages" href="http://en.wikipedia.org/wiki/Programming_languages">programming languages</a>.  The <code>json.org</code> website provides a comprehensive listing of  existing JSON <a title="Binding (computer science)" href="http://en.wikipedia.org/wiki/Binding_%28computer_science%29">bindings</a>, organized by language.</p>
<p>In December 2005, <a title="Yahoo!" href="http://en.wikipedia.org/wiki/Yahoo%21">Yahoo!</a> began offering some of its <a title="Web service" href="http://en.wikipedia.org/wiki/Web_service">web  services</a> optionally in JSON.<sup id="cite_ref-yahoo_1-0"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-yahoo-1">[2]</a></sup> <a title="Google" href="http://en.wikipedia.org/wiki/Google">Google</a> started offering JSON feeds for its <a title="GData" href="http://en.wikipedia.org/wiki/GData">GData</a> web  protocol in December 2006.<sup id="cite_ref-Google_2-0"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-Google-2">[3]</a></sup> JSON is preferred by <a title="Twitter" href="http://en.wikipedia.org/wiki/Twitter">Twitter</a> over <a title="XML" href="http://en.wikipedia.org/wiki/XML">XML</a> in its  streaming API. <sup id="cite_ref-twitter_3-0"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-twitter-3">[4]</a></sup></p>
<h2>[<a title="Edit section: Data types, syntax and example" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=2">edit</a>] Data types,  syntax and example</h2>
<p>JSON&#8217;s basic types are:</p>
<ul>
<li>Number (integer, real, or <a title="Floating  point" href="http://en.wikipedia.org/wiki/Floating_point">floating point</a>)</li>
<li><a title="String (computer science)" href="http://en.wikipedia.org/wiki/String_%28computer_science%29">String</a> (double-quoted <a title="Unicode" href="http://en.wikipedia.org/wiki/Unicode">Unicode</a> with backslash <a title="Escape character" href="http://en.wikipedia.org/wiki/Escape_character">escaping</a>)</li>
<li><a title="Boolean datatype" href="http://en.wikipedia.org/wiki/Boolean_datatype">Boolean</a> (<code>true</code> and <code>false</code>)</li>
<li><a title="Array data structure" href="http://en.wikipedia.org/wiki/Array_data_structure">Array</a> (an ordered sequence of values,  comma-separated and enclosed in <a title="Square  bracket" href="http://en.wikipedia.org/wiki/Square_bracket">square brackets</a>)</li>
<li><a title="Associative array" href="http://en.wikipedia.org/wiki/Associative_array">Object</a> (collection of key:value pairs,  comma-separated and enclosed in <a title="Curly brace" href="http://en.wikipedia.org/wiki/Curly_brace">curly braces</a>)</li>
<li><code><a title="Null (computer programming)" href="http://en.wikipedia.org/wiki/Null_%28computer_programming%29">null</a></code></li>
</ul>
<p>The following example shows the JSON representation of an object that  describes a person. The object has string fields for first name and  last name, contains an object representing the person&#8217;s address, and  contains a list (an array) of phone number objects.</p>
<div dir="ltr">
<div>
<pre>{
     "firstName": "John",
     "lastName": "Smith",
     "age": 25,
     "address": {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": "10021"
     },
     "phoneNumber": [
         { "type": "home", "number": "212 555-1234" },
         { "type": "fax", "number": "646 555-4567" }
     ],
     "newSubscription": false,
     "companyName": null
 }
</pre>
</div>
</div>
<p>A possible equivalent for the above in XML could be:</p>
<div dir="ltr">
<div>
<pre>&lt;Person&gt;
  &lt;firstName&gt;John&lt;/firstName&gt;
  &lt;lastName&gt;Smith&lt;/lastName&gt;
  &lt;age&gt;25&lt;/age&gt;
  &lt;address&gt;
    &lt;streetAddress&gt;21 2nd Street&lt;/streetAddress&gt;
    &lt;city&gt;New York&lt;/city&gt;
    &lt;state&gt;NY&lt;/state&gt;
    &lt;postalCode&gt;10021&lt;/postalCode&gt;
  &lt;/address&gt;
  &lt;phoneNumber type="home"&gt;212 555-1234&lt;/phoneNumber&gt;
  &lt;phoneNumber type="fax"&gt;646 555-4567&lt;/phoneNumber&gt;
  &lt;newSubscription&gt;false&lt;/newSubscription&gt;
  &lt;companyName /&gt;
&lt;/Person&gt;
</pre>
</div>
</div>
<p>Per the <a title="Request for Comments" href="http://en.wikipedia.org/wiki/Request_for_Comments">RFC</a>, the <a title="Internet  media type" href="http://en.wikipedia.org/wiki/Internet_media_type">MIME type</a> to be used when transferring a JSON file using  HTTP is <code>application/json</code>.</p>
<p>Since JSON is a subset of JavaScript it is possible, but not  recommended, to parse the JSON text into an object by invoking  JavaScript&#8217;s <code><a title="Eval" href="http://en.wikipedia.org/wiki/Eval">eval()</a></code> function. For example, assume the above  JSON text segment is contained in the JavaScript string variable <code>contact</code>.  Creating a JavaScript object, p, from the JSON data could be done with  the statement:</p>
<div dir="ltr">
<div>
<pre> var p = eval("(" + contact + ")");
</pre>
</div>
</div>
<p>The <code>contact</code> variable must be wrapped in parentheses to  avoid an ambiguity in JavaScript&#8217;s syntax.<sup id="cite_ref-4"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-4">[5]</a></sup></p>
<p>The recommended way, however, is to use a JSON <a title="Parser" href="http://en.wikipedia.org/wiki/Parser">parser</a>. Parsers are now built into advanced  browsers like Firefox 3.5 and IE 8.0.</p>
<div dir="ltr">
<div>
<pre>  var p = JSON.parse(contact);
</pre>
</div>
</div>
<p>The parsed data fields are accessible using standard JavaScript  syntax: <code>p.firstName</code>, <code>p.address.city</code>, <code>p.phoneNumbers[0]</code> etc.</p>
<p>Unless you absolutely trust the source of the text, and you have a  need to parse and accept text that is not strictly JSON-compliant, you  should avoid <code>eval()</code> and use <code>JSON.parse()</code> or  another JSON-specific parser instead. A JSON parser will recognize only  JSON text and will reject other text, which could contain malevolent  JavaScript. In browsers that provide native JSON support, JSON parsers  are also much faster than eval. It is expected that native JSON support  will be included in the next ECMAScript standard. <a rel="nofollow" href="http://www.json.org/js.html">[1]</a></p>
<h2>[<a title="Edit section: JSON schema" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=3">edit</a>] JSON schema</h2>
<p>There are several ways to verify the structure and data types inside a  JSON object, much like an <a title="XML schema" href="http://en.wikipedia.org/wiki/XML_schema">XML  schema</a>.</p>
<p>JSON Schema<sup id="cite_ref-5"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-5">[6]</a></sup> is a specification for a JSON-based format for defining the structure  of JSON data. JSON Schema provides a contract for what JSON data is  required for a given application and how it can be modified, much like  what XML Schema provides for XML. JSON Schema is intended to provide  validation, documentation, and interaction control of JSON data. JSON  Schema is based on the concepts from <a title="XML  Schema (W3C)" href="http://en.wikipedia.org/wiki/XML_Schema_%28W3C%29">XML Schema</a>, <a title="RelaxNG" href="http://en.wikipedia.org/wiki/RelaxNG">RelaxNG</a>, and <a title="Kwalify (page does not exist)" href="http://en.wikipedia.org/w/index.php?title=Kwalify&amp;action=edit&amp;redlink=1">Kwalify</a>, but is  intended to be JSON-based, so that JSON data in the form of a schema can  be used to validate JSON data, the same serialization/deserialization  tools can be used for the schema and data, and it can be self  descriptive.</p>
<h2>[<a title="Edit section: Using JSON in Ajax" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=4">edit</a>] Using JSON in Ajax</h2>
<p>The following JavaScript code shows how the client can use an <a title="XMLHttpRequest" href="http://en.wikipedia.org/wiki/XMLHttpRequest">XMLHttpRequest</a> to request an object in JSON  format from the server. (The server-side programming is omitted; it has  to be set up to respond to requests at <code>url</code> with a  JSON-formatted string.)</p>
<div dir="ltr">
<div>
<pre>var the_object = {};
var http_request = new XMLHttpRequest();
http_request.open( "GET", url, true );
http_request.onreadystatechange = function () {
    if ( http_request.readyState == 4 &amp;&amp; http_request.status == 200 ) {
            the_object = JSON.parse( http_request.responseText );
        }
};
http_request.send(null);
</pre>
</div>
</div>
<p>Note that the use of <a title="XMLHttpRequest" href="http://en.wikipedia.org/wiki/XMLHttpRequest">XMLHttpRequest</a> in this example is not <a title="Cross-browser" href="http://en.wikipedia.org/wiki/Cross-browser">cross-browser</a> compatible; <a title="Syntax" href="http://en.wikipedia.org/wiki/Syntax">syntactic</a> variations are available for <a title="Internet  Explorer" href="http://en.wikipedia.org/wiki/Internet_Explorer">Internet Explorer</a>, <a title="Opera  (web browser)" href="http://en.wikipedia.org/wiki/Opera_%28web_browser%29">Opera</a>, <a title="Safari (web browser)" href="http://en.wikipedia.org/wiki/Safari_%28web_browser%29">Safari</a>, and <a title="Mozilla" href="http://en.wikipedia.org/wiki/Mozilla">Mozilla</a>-based  browsers. The usefulness of XMLHttpRequest is limited by the <a title="Same  origin policy" href="http://en.wikipedia.org/wiki/Same_origin_policy">same origin policy</a>: the URL replying to the request  must reside within the same DNS domain as the server that hosts the page  containing the request. Alternatively, the <a title="JSONP" href="http://en.wikipedia.org/wiki/JSONP">JSONP</a> approach incorporates the use of an  encoded callback function passed between the client and server to allow  the client to load JSON-encoded data from third-party domains and to  notify the caller function upon completion, although this imposes some  security risks and additional requirements upon the server.</p>
<p>Browsers can also use <code>&lt;<a title="Iframe" href="http://en.wikipedia.org/wiki/Iframe">iframe</a>&gt;</code> elements to asynchronously  request JSON data in a <a title="Cross-browser" href="http://en.wikipedia.org/wiki/Cross-browser">cross-browser</a> fashion, or use simple <code>&lt;form action="url_to_cgi_script"  target="name_of_hidden_iframe"&gt;</code> submissions. These approaches  were prevalent prior to the advent of widespread support for  XMLHttpRequest.</p>
<p>Dynamic <a title="HTML element" href="http://en.wikipedia.org/wiki/HTML_element"><code>&lt;script&gt;</code></a> tags can also be  used to transport JSON data. With this technique it is possible to get  around the <a title="Same origin policy" href="http://en.wikipedia.org/wiki/Same_origin_policy">same origin policy</a> but it is insecure. <a rel="nofollow" href="http://json.org/JSONRequest.html">JSONRequest</a> has been proposed as a safer alternative.</p>
<h2>[<a title="Edit section: Security issues" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=5">edit</a>] Security issues</h2>
<p>Although JSON is intended as a data serialization format, its design  as a subset of the JavaScript programming language poses several  security concerns. These concerns center on the use of a JavaScript  interpreter to dynamically execute JSON text as JavaScript, thus  exposing a program to errant or malicious script contained therein—often  a chief concern when dealing with data retrieved from the internet.  While not the only way to process JSON, it is an easy and popular  technique, stemming from JSON&#8217;s design to be compatible with  JavaScript&#8217;s eval() function, and illustrated by the following code  examples.</p>
<h3>[<a title="Edit section: JavaScript eval()" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=6">edit</a>] JavaScript <code>eval()</code></h3>
<p>Because all JSON-formatted text is also syntactically legal  JavaScript code, an easy way for a JavaScript program to parse  JSON-formatted data is to use the built-in JavaScript <code>eval()</code> function, which was designed to evaluate JavaScript expressions. Rather  than using a JSON-specific parser, the JavaScript interpreter itself is  used to <em>execute</em> the JSON data to produce native JavaScript  objects.</p>
<p>The eval technique is subject to <a title="Vulnerability (computing)" href="http://en.wikipedia.org/wiki/Vulnerability_%28computing%29">security vulnerabilities</a> if the  data and the entire JavaScript environment is not within the control of a  single <a title="Trusted system" href="http://en.wikipedia.org/wiki/Trusted_system">trusted source</a>. If the data is itself not  trusted, for example, it may be subject to malicious JavaScript <a title="Code  injection" href="http://en.wikipedia.org/wiki/Code_injection">code injection</a> attacks; unless some additional means is  used to validate the data first. <a title="Regular  expression" href="http://en.wikipedia.org/wiki/Regular_expression">Regular expressions</a> are sometimes used to perform this  check prior to invoking <code>eval</code>. Also, such breaches of trust  may create vulnerabilities for <a title="Data theft" href="http://en.wikipedia.org/wiki/Data_theft">data  theft</a>, <a title="Digital identity" href="http://en.wikipedia.org/wiki/Digital_identity">authentication forgery</a>, and other potential  misuse of data and resources. The RFC that defines JSON (<a href="http://tools.ietf.org/html/rfc4627">RFC 4627</a>) suggests using the following code to  validate JSON before eval&#8217;ing it (the variable &#8216;text&#8217; is the input  JSON):<sup id="cite_ref-6"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-6">[7]</a></sup></p>
<div dir="ltr">
<div>
<pre>var my_JSON_object = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
text.replace(/"(\\.|[^"\\])*"/g, ''))) &amp;&amp;
eval('(' + text + ')');
</pre>
</div>
</div>
<p>A new function, <code>parseJSON()</code>, has been proposed as a  safer alternative to <code>eval</code>, as it is specifically intended  to process JSON data and not JavaScript. It was to be included in the  Fourth Edition of the <a title="ECMAScript" href="http://en.wikipedia.org/wiki/ECMAScript">ECMAScript</a> standard,<sup id="cite_ref-7"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-7">[8]</a></sup> though it is available now as a JavaScript library at <a rel="nofollow" href="http://www.json.org/json2.js">http://www.JSON.org/json2.js</a> and will be in the Fifth Edition of <a title="ECMAScript" href="http://en.wikipedia.org/wiki/ECMAScript">ECMAScript</a>.<sup title="This claim needs references to reliable  sources from July 2009">[<em><a title="Wikipedia:Citation needed" href="http://en.wikipedia.org/wiki/Wikipedia:Citation_needed">citation needed</a></em>]</sup></p>
<h3>[<a title="Edit section: Native JSON" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=7">edit</a>] Native JSON</h3>
<p>Recent web browsers now either have or are working on native JSON  encoding/decoding which removes the <code>eval()</code> security problem  above. Native JSON is generally faster compared to the JavaScript  libraries commonly used before. As of June 2009 the following browsers  have or will have native JSON support:</p>
<ul>
<li><a title="Mozilla Firefox 3.5" href="http://en.wikipedia.org/wiki/Mozilla_Firefox_3.5">Mozilla Firefox 3.5</a>+<sup id="cite_ref-8"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-8">[9]</a></sup></li>
<li>Microsoft <a title="Internet Explorer" href="http://en.wikipedia.org/wiki/Internet_Explorer">Internet Explorer</a> 8<sup id="cite_ref-9"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-9">[10]</a></sup></li>
<li><a title="Webkit" href="http://en.wikipedia.org/wiki/Webkit">Webkit</a>-based browsers (e.g. Google Chrome, Apple  Safari)<sup id="cite_ref-10"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-10">[11]</a></sup></li>
</ul>
<p>At least 4 popular JavaScript libraries have committed to use native  JSON if available:</p>
<ul>
<li><a title="Yahoo! UI Library" href="http://en.wikipedia.org/wiki/Yahoo%21_UI_Library">Yahoo! UI Library</a><sup id="cite_ref-11"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-11">[12]</a></sup></li>
<li><a title="JQuery" href="http://en.wikipedia.org/wiki/JQuery">jQuery</a><sup id="cite_ref-12"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-12">[13]</a></sup></li>
<li><a title="Dojo  Toolkit" href="http://en.wikipedia.org/wiki/Dojo_Toolkit">Dojo Toolkit</a><sup id="cite_ref-13"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-13">[14]</a></sup></li>
<li><a title="Mootools" href="http://en.wikipedia.org/wiki/Mootools">mootools</a><sup id="cite_ref-14"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-14">[15]</a></sup></li>
</ul>
<h2>[<a title="Edit section: Comparison with other formats" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=8">edit</a>] Comparison with  other formats</h2>
<div>Main article: <a title="Lightweight markup language" href="http://en.wikipedia.org/wiki/Lightweight_markup_language">lightweight markup language</a></div>
<h3>[<a title="Edit section: XML" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=9">edit</a>] XML</h3>
<p><a title="XML" href="http://en.wikipedia.org/wiki/XML">XML</a> is  often used to describe structured data and to serialize objects. Various  XML-based protocols exist to represent the same kind of data structures  as JSON for the same kind of data interchange purposes. However, XML  being a general-purpose <a title="Markup  language" href="http://en.wikipedia.org/wiki/Markup_language">markup language</a>, they are syntactically more complex and  bigger in file size than JSON, which, in contrast, is specifically  designed for data interchange.</p>
<p>Both lack an explicit mechanism for representing <a title="Binary  large object" href="http://en.wikipedia.org/wiki/Binary_large_object">large binary</a> <a title="Data type" href="http://en.wikipedia.org/wiki/Data_type">data  types</a> such as image data (although binary data can be serialized in  either case by applying a general-purpose <a title="Binary-to-text encoding" href="http://en.wikipedia.org/wiki/Binary-to-text_encoding">binary-to-text encoding scheme</a>).  JSON lacks references (something XML has via extensions like XLink and  XPointer) and has no standard path notation comparable to <a title="XPath" href="http://en.wikipedia.org/wiki/XPath">XPath</a>.</p>
<h3>[<a title="Edit section: YAML" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=10">edit</a>] YAML</h3>
<p>Both functionally and syntactically, <a title="YAML" href="http://en.wikipedia.org/wiki/YAML">YAML</a> is  effectively a superset of JSON.<sup id="cite_ref-15"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-15">[16]</a></sup> The common YAML library (Syck) also parses JSON.<sup id="cite_ref-16"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-16">[17]</a></sup> Prior to YAML version 1.2, YAML was not quite a perfect superset of  JSON, primarily because it lacked native handling of <a title="UTF-32" href="http://en.wikipedia.org/wiki/UTF-32">UTF-32</a> and required comma separators to be  followed by a space.</p>
<p>The most distinguishing point of comparison is that YAML offers the  following syntax enrichments which have no corresponding expression in  JSON:</p>
<dl>
<dt>Relational:</dt>
<dd>YAML offers syntax for relational data: rather than repeating  identical data later in a document, a YAML document can refer to an  anchor earlier in the file/stream. Recursive structures (for example, an  array containing itself) can be expressed this way. For example, a film  data base might list actors (and their attributes) under a Movie&#8217;s  cast, and also list Movies (and their attributes) under an Actor&#8217;s  portfolio.</dd>
<dt>Extensible:</dt>
<dd>YAML also offers extensible data types beyond primitives (i.e.,  strings, floats, ints, bools) which can include class-type declarations.</dd>
<dt>Blocks:</dt>
<dd>YAML uses a block-indent syntax to allow formatting of structured  data without use of additional characters (ie: braces, brackets,  quotation marks, etc.). Besides giving YAML a different appearance than  JSON, this block-indent device permits the encapsulation of text from  other markup languages or even JSON in the other languages native  literal style and without escaping of colliding <a title="Sigil (computer programming)" href="http://en.wikipedia.org/wiki/Sigil_%28computer_programming%29">sigils</a>.</dd>
</dl>
<h2>[<a title="Edit section: Efficiency" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=11">edit</a>] Efficiency</h2>
<p>JSON is primarily used for communicating data over the Internet, but  has certain characteristics that may limit its efficiency for this  purpose. Most of the limitations are general limitations of textual data  formats and also apply to XML and YAML. For example, decoding must be  done on a character-by-character basis, and the standard has no  provision for <a title="Data compression" href="http://en.wikipedia.org/wiki/Data_compression">data compression</a>, interning of strings, or  object references. Compression can, of course, be applied to the JSON  formatted data.</p>
<p>In practice performance can be <a rel="nofollow" href="http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking">comparable to that of similar  binary data formats</a> and often depends more on implementation quality  than on the theoretical limitations of formats.</p>
<h2>[<a title="Edit section: JSONP" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=12">edit</a>] JSONP</h2>
<p><strong>JSONP</strong> or &#8220;JSON with padding&#8221; is a complement to the base JSON  data format, a <em>usage pattern</em> that allows a page to request and  more meaningfully use JSON from a server other than the primary server.</p>
<p>Under the <a title="Same origin policy" href="http://en.wikipedia.org/wiki/Same_origin_policy">same origin policy</a>, a web page served  from domain1.com cannot normally connect to or communicate with a server  other than domain1.com. An exception is <a title="HTML" href="http://en.wikipedia.org/wiki/HTML">HTML</a> <a title="HTML element" href="http://en.wikipedia.org/wiki/HTML_element"><code>&lt;script&gt;</code></a> tags, which can retrieve data from locations other than domain1.com.  Taking advantage of the open policy for <a title="HTML element" href="http://en.wikipedia.org/wiki/HTML_element"><code>&lt;script&gt;</code></a> tags, some pages use them to retrieve JSON from other origins. Without  JSONP, a script URL that returns JSON just embeds a data statement into a  browser page. In other words, the browser would receive something like:</p>
<div dir="ltr">
<div>
<pre>   {"Name":"Cheeso","Rank":7}
</pre>
</div>
</div>
<p>&#8230; which may be interesting but is just data, and has no externally  detectable effect in the browser&#8217;s execution context when received and  evaluated.</p>
<p>With JSONP, the browser provides a Javascript prefix to the server;  by convention, the browser provides the prefix as a named query string  argument in its request to the server, e.g.,</p>
<div dir="ltr">
<div>
<pre>    &lt;script type='text/javascript' src='http://domain1.com/getjson?jsonp=parseResponse'&gt;
</pre>
</div>
</div>
<p>The server then wraps its JSON response with this prefix, or  &#8220;padding&#8221;, before sending it to the browser. When the browser receives  the wrapped response from the server it is now a script, rather than  simply a data declaration. In this example, what is received is</p>
<div dir="ltr">
<div>
<pre>    parseResponse({"Name":"Cheeso","Rank":7})
</pre>
</div>
</div>
<p>&#8230;which can cause a change of state within the browser&#8217;s execution  context, because it invokes a method.</p>
<p>While the padding (prefix) is <em>typically</em> the name of a callback  function that is defined within the execution context of the browser,  it may also be a variable assignment, an if statement, or any other  Javascript statement prefix.</p>
<p>The original proposal for JSONP appears to have been made by Bob  Ippolito in 2005 <sup id="cite_ref-17"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-17">[18]</a></sup> and is now used by many <a title="Web 2.0" href="http://en.wikipedia.org/wiki/Web_2.0">Web 2.0</a> applications such as <a title="Dojo Toolkit" href="http://en.wikipedia.org/wiki/Dojo_Toolkit">Dojo  Toolkit</a> Applications, Google Web Toolkit Applications<sup id="cite_ref-18"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-18">[19]</a></sup> and Web Services. Further extensions of this protocol have been  proposed by considering additional input arguments as, for example, is  the case of JSONPP<sup id="cite_ref-19"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-19">[20]</a></sup> supported by <a title="S3DB" href="http://en.wikipedia.org/wiki/S3DB">S3DB</a> web services.</p>
<p>Because JSONP makes use of script tags, calls are essentially open to  the world. For that reason, JSONP may be inappropriate to carry  sensitive data.<sup id="cite_ref-RIAspot_20-0"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-RIAspot-20">[21]</a></sup></p>
<p>Including script tags from remote sites allows the remote sites to  inject <strong>any</strong> content into a website. If the remote sites have  vulnerabilities that allow JavaScript injection, the original site can  also be affected.</p>
<h3>[<a title="Edit section: Cross-site request forgery" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=13">edit</a>] Cross-site request  forgery</h3>
<p>Naïve deployments of JSONP are subject to <a title="Cross-site request forgery" href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">cross-site request forgery</a> attacks (<a title="CSRF" href="http://en.wikipedia.org/wiki/CSRF">CSRF</a> or <a title="XSRF" href="http://en.wikipedia.org/wiki/XSRF">XSRF</a>).<sup id="cite_ref-21"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-21">[22]</a></sup> Because the <a title="HTML" href="http://en.wikipedia.org/wiki/HTML">HTML</a> <a title="HTML  element" href="http://en.wikipedia.org/wiki/HTML_element"><code>&lt;script&gt;</code></a> tag does not respect the <a title="Same  origin policy" href="http://en.wikipedia.org/wiki/Same_origin_policy">same origin policy</a> in web browser implementations, a  malicious page can request and obtain JSON data belonging to another  site. This will allow the JSON-encoded data to be evaluated in the  context of the malicious page, possibly divulging passwords or other  sensitive data if the user is currently logged into the other site.</p>
<p>This is only a problem if the JSON-encoded data contains sensitive  information that should not be disclosed to a third party, and the  server depends on the browser&#8217;s Same Origin Policy to block the delivery  of the data in the case of an improper request. There is no problem if  the server determines the propriety of the request itself, only putting  the data on the wire if the request is proper. <a title="HTTP cookie" href="http://en.wikipedia.org/wiki/HTTP_cookie">Cookies</a> are not by themselves adequate for determining if a request was  authorized. Exclusive use of cookies is subject to <a title="Cross-site request forgery" href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">cross-site request forgery</a>.</p>
<h2>[<a title="Edit section: Object references" href="http://en.wikipedia.org/w/index.php?title=JSON&amp;action=edit&amp;section=14">edit</a>] Object references</h2>
<p>The JSON standard does not support object <a title="Reference (computer science)" href="http://en.wikipedia.org/wiki/Reference_%28computer_science%29">references</a>, but the <a title="Dojo Toolkit" href="http://en.wikipedia.org/wiki/Dojo_Toolkit">Dojo  Toolkit</a> illustrates how conventions can be adopted to support such  references using standard JSON. Specifically, the <a rel="nofollow" href="http://api.dojotoolkit.org/jsdoc/1.2/dojox.json.ref">dojox.json.ref</a> module provides  support for several forms of referencing including <a title="Circular  reference" href="http://en.wikipedia.org/wiki/Circular_reference">circular</a>, multiple, inter-message, and <a title="Lazy  evaluation" href="http://en.wikipedia.org/wiki/Lazy_evaluation">lazy</a> referencing.<sup id="cite_ref-22"><a href="http://en.wikipedia.org/wiki/JSON#cite_note-22">[23]</a></sup></p>
]]></content:encoded>
			<wfw:commentRss>http://witslog.com/wiki/technical/json/json/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

