<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Couto</id>
	<title>Medien Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Couto"/>
	<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/Special:Contributions/Couto"/>
	<updated>2026-04-10T22:57:49Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12118</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12118"/>
		<updated>2010-07-07T21:11:27Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Send the form to PHP with AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Post the tweet using a PHP Twitter Library]]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;sendTweet.php&amp;quot; method=&amp;quot;post&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;username&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;pasword&amp;quot; name=&amp;quot;password&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;password&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;textarea name=&amp;quot;tweet&amp;quot; value=&amp;quot;tweet&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; id=&amp;quot;submit&amp;quot; value=&amp;quot;Continue &amp;amp;rarr;&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;json2.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;jquery-1.4.2.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			obj = new Object;	//Going to do an object only to use the parser&lt;br /&gt;
			obj.username = $(&#039;#username&#039;).val();&lt;br /&gt;
			obj.password = $(&#039;#password&#039;).val()&lt;br /&gt;
			obj.tweet = $(&#039;#tweet&#039;).val();&lt;br /&gt;
			obj2string = JSON.stringify(obj);	//convert object to json string&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;As you can see, i&#039;m using the parser to safely convert a javascript object to a JSON String&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Send the form to PHP with AJAX===&lt;br /&gt;
Here i&#039;m sending the previous JSON string to a PHP file with AJAX, and parsing the twitter answer into a javascript object. To every request, Twitter responds with a JSON, in this case, the JSON file contains the info about the tweet we posted using PHP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
	$.post(&amp;quot;sendTweet.php&amp;quot;,{&amp;quot;sendedTweet&amp;quot;:obj2string},function(data)){&lt;br /&gt;
		tweet = JSON.parse(data);	//convert json string to object&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;On the other side in PHP, we get the values, and we use a PHP Library to send the tweet, libraries change according to its programmer, so it&#039;s always a good idea to read the instructions.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;On the other hand, if you don&#039;t want to use a library you can always use the cURL method showed above to do an authenticated post&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
//Currently using the Tijs Verkoyen library http://classes.verkoyen.eu/twitter/&lt;br /&gt;
&lt;br /&gt;
if(isset($_POST[&#039;sendedTweet&#039;])){&lt;br /&gt;
&lt;br /&gt;
	$tweet = json_decode($_POST[&#039;sendedTweet&#039;]); #decode the JSON string&lt;br /&gt;
&lt;br /&gt;
	$username = $tweet[&#039;username&#039;];&lt;br /&gt;
	$password = $tweet[&#039;password&#039;];&lt;br /&gt;
	$tweet = $tweet[&#039;tweet&#039;];&lt;br /&gt;
&lt;br /&gt;
	include &amp;quot;twitter_library.php&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
	$twi_user = new Twitter(&amp;quot;$username&amp;quot;,&amp;quot;$password&amp;quot;);&lt;br /&gt;
	$user_text = $tweet;&lt;br /&gt;
	$twi_user-&amp;gt;updateStatus($user_text);&lt;br /&gt;
&lt;br /&gt;
	echo $twi_user&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And that&#039;s pretty much it. I hope i was able to make myself clear during this article, however if you have any doubt please feel free to contact me to [mailto:lcouto87@gmail.com here]&amp;lt;/p&amp;gt;&lt;br /&gt;
==Resources==&lt;br /&gt;
[http://www.json.org  JSON Official Website]&lt;br /&gt;
[http://www.twitter.com Twitter.com]&lt;br /&gt;
[http://dev.twitter.com Twitter Developer Page]&lt;br /&gt;
[http://www.php.net PHP.net]&lt;br /&gt;
[http://www.jquery.com jQuery.com]&lt;br /&gt;
&lt;br /&gt;
--[[User:Couto|Couto]] 21:07, 7 July 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12117</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12117"/>
		<updated>2010-07-07T21:07:41Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Send the form to PHP with AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Post the tweet using a PHP Twitter Library]]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;sendTweet.php&amp;quot; method=&amp;quot;post&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;username&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;pasword&amp;quot; name=&amp;quot;password&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;password&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;textarea name=&amp;quot;tweet&amp;quot; value=&amp;quot;tweet&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; id=&amp;quot;submit&amp;quot; value=&amp;quot;Continue &amp;amp;rarr;&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;json2.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;jquery-1.4.2.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			obj = new Object;	//Going to do an object only to use the parser&lt;br /&gt;
			obj.username = $(&#039;#username&#039;).val();&lt;br /&gt;
			obj.password = $(&#039;#password&#039;).val()&lt;br /&gt;
			obj.tweet = $(&#039;#tweet&#039;).val();&lt;br /&gt;
			obj2string = JSON.stringify(obj);	//convert object to json string&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;As you can see, i&#039;m using the parser to safely convert a javascript object to a JSON String&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Send the form to PHP with AJAX===&lt;br /&gt;
Here i&#039;m sending the previous JSON string to a PHP file with AJAX, and parsing the twitter answer into a javascript object. To every request, Twitter responds with a JSON, in this case, the JSON file contains the info about the tweet we posted using PHP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
	$.post(&amp;quot;sendTweet.php&amp;quot;,{&amp;quot;sendedTweet&amp;quot;:obj2string},function(data)){&lt;br /&gt;
		tweet = JSON.parse(data);	//convert json string to object&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;On the other side in PHP, we get the values, and we use a PHP Library to send the tweet, libraries change according to its programmer, so it&#039;s always a good idea to read the instructions.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;On the other hand, if you don&#039;t want to use a library you can always use the cURL method showed above to do an authenticated post&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
//Currently using the Tijs Verkoyen library http://classes.verkoyen.eu/twitter/&lt;br /&gt;
&lt;br /&gt;
if(isset($_POST[&#039;sendedTweet&#039;])){&lt;br /&gt;
&lt;br /&gt;
	$tweet = json_decode($_POST[&#039;sendedTweet&#039;]); #decode the JSON string&lt;br /&gt;
&lt;br /&gt;
	$username = $tweet[&#039;username&#039;];&lt;br /&gt;
	$password = $tweet[&#039;password&#039;];&lt;br /&gt;
	$tweet = $tweet[&#039;tweet&#039;];&lt;br /&gt;
&lt;br /&gt;
	include &amp;quot;twitter_library.php&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
	$twi_user = new Twitter(&amp;quot;$username&amp;quot;,&amp;quot;$password&amp;quot;);&lt;br /&gt;
	$user_text = $tweet;&lt;br /&gt;
	$twi_user-&amp;gt;updateStatus($user_text);&lt;br /&gt;
&lt;br /&gt;
	echo $twi_user&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And that&#039;s pretty much it. I hope i was able to make myself clear during this article, however if you have any doubt please feel free to contact me to [mailto:lcouto87@gmail.com here]&amp;lt;/p&amp;gt;&lt;br /&gt;
--[[User:Couto|Couto]] 21:07, 7 July 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12115</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12115"/>
		<updated>2010-07-07T20:35:58Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;lol.php&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lol&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lol&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lmao&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lmao&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; id=&amp;quot;submit&amp;quot; value=&amp;quot;Continue &amp;amp;rarr;&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;json2.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;jquery-1.4.2.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			obj = new Object;	//Going to do an object only to use the parser&lt;br /&gt;
			obj.input1 = $(&#039;#lol&#039;).val();&lt;br /&gt;
			obj.input2 = $(&#039;#lmao&#039;).val()&lt;br /&gt;
			obj2string = JSON.stringify(obj);	//convert object to json string&lt;br /&gt;
			alert(obj2string);&lt;br /&gt;
			$.post(&amp;quot;sendTweet.php&amp;quot;,obj2string,function(data)){&lt;br /&gt;
				tweet = JSON.parse(data);	//convert json string to object&lt;br /&gt;
			}&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12114</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12114"/>
		<updated>2010-07-07T20:35:18Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;lol.php&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lol&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lol&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lmao&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lmao&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; id=&amp;quot;submit&amp;quot; value=&amp;quot;Continue &amp;amp;rarr;&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;json2.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;jquery-1.4.2.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			obj = new Object;		//Going to do an object only to use the parser&lt;br /&gt;
			obj.input1 = $(&#039;#lol&#039;).val();&lt;br /&gt;
			obj.input2 = $(&#039;#lmao&#039;).val()&lt;br /&gt;
			obj2string = JSON.stringify(obj);	//convert object to json string&lt;br /&gt;
			alert(obj2string);&lt;br /&gt;
			$.post(&amp;quot;sendTweet.php&amp;quot;,obj2string,function(data)){&lt;br /&gt;
				tweet = JSON.parse(data);	//convert json string to object&lt;br /&gt;
			}&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12113</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12113"/>
		<updated>2010-07-07T20:34:04Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;lol.php&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lol&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lol&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lmao&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lmao&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; id=&amp;quot;submit&amp;quot; value=&amp;quot;Continue &amp;amp;rarr;&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;http://www.JSON.org/json2.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;http://code.jquery.com/jquery-1.4.2.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			obj = new Object;	//Going to do an object only to use the parser&lt;br /&gt;
			obj.input1 = $(&#039;#lol&#039;).val();&lt;br /&gt;
			obj.input2 = $(&#039;#lmao&#039;).val()&lt;br /&gt;
			obj2string = JSON.stringify(obj);//convert object to json string&lt;br /&gt;
			alert(obj2string);&lt;br /&gt;
			$.post(&amp;quot;sendTweet.php&amp;quot;,obj2string,function(data)){&lt;br /&gt;
				tweet = JSON.parse(data);//convert json string to object&lt;br /&gt;
			}&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12112</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12112"/>
		<updated>2010-07-07T20:31:59Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;lol.php&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lol&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lol&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lmao&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lmao&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; id=&amp;quot;submit&amp;quot; value=&amp;quot;Continue &amp;amp;rarr;&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;http://www.JSON.org/json2.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;http://code.jquery.com/jquery-1.4.2.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			obj = new Object;		//Going to do an object only to use the parser&lt;br /&gt;
			obj.input1 = $(&#039;#lol&#039;).val();&lt;br /&gt;
			obj.input2 = $(&#039;#lmao&#039;).val()&lt;br /&gt;
			obj2string = JSON.stringify(obj);//convert object to json string&lt;br /&gt;
			alert(obj2string);&lt;br /&gt;
			$.post(&amp;quot;sendTweet.php&amp;quot;,obj2string,function(data)){&lt;br /&gt;
				tweet = JSON.parse(data);//convert json string to object&lt;br /&gt;
			}&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12111</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12111"/>
		<updated>2010-07-07T20:31:18Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;lol.php&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lol&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lol&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lmao&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lmao&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; id=&amp;quot;submit&amp;quot; value=&amp;quot;Continue &amp;amp;rarr;&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;http://www.JSON.org/json2.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;http://code.jquery.com/jquery-1.4.2.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			obj = new Object;			//Going to do an object only to use the parser&lt;br /&gt;
			obj.input1 = $(&#039;#lol&#039;).val();&lt;br /&gt;
			obj.input2 = $(&#039;#lmao&#039;).val()&lt;br /&gt;
			obj2string = JSON.stringify(obj);	//convert object to json string&lt;br /&gt;
			alert(obj2string);&lt;br /&gt;
			$.post(&amp;quot;sendTweet.php&amp;quot;,obj2string,function(data)){&lt;br /&gt;
				tweet = JSON.parse(data);	//convert json string to object&lt;br /&gt;
			}&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12110</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12110"/>
		<updated>2010-07-07T20:30:32Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;lol.php&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lol&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lol&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lmao&amp;quot; value=&amp;quot;&amp;quot; id=&amp;quot;lmao&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; id=&amp;quot;submit&amp;quot; value=&amp;quot;Continue &amp;amp;rarr;&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;http://www.JSON.org/json2.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot; src=&amp;quot;http://code.jquery.com/jquery-1.4.2.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			obj = new Object;				//Going to do an object only to use the parser&lt;br /&gt;
			obj.input1 = $(&#039;#lol&#039;).val();&lt;br /&gt;
			obj.input2 = $(&#039;#lmao&#039;).val()&lt;br /&gt;
			obj2string = JSON.stringify(obj);	//convert object to json string&lt;br /&gt;
			alert(obj2string);&lt;br /&gt;
			$.post(&amp;quot;sendTweet.php&amp;quot;,obj2string,function(data)){&lt;br /&gt;
				tweet = JSON.parse(data);		//convert json string to object&lt;br /&gt;
			}&lt;br /&gt;
		});&lt;br /&gt;
	});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12109</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12109"/>
		<updated>2010-07-07T18:54:11Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; value=&amp;quot;username&amp;quot; id=&amp;quot;tweet&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;password&amp;quot; value=&amp;quot;password&amp;quot; id=&amp;quot;tweet&amp;quot;&amp;gt;	&lt;br /&gt;
	&amp;lt;textarea name=&amp;quot;tweet&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Send&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jsonparser.js&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e)){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			&lt;br /&gt;
		}&lt;br /&gt;
	})&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12108</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12108"/>
		<updated>2010-07-07T18:53:29Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; value=&amp;quot;username&amp;quot; id=&amp;quot;tweet&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;password&amp;quot; value=&amp;quot;password&amp;quot; id=&amp;quot;tweet&amp;quot;&amp;gt;	&lt;br /&gt;
	&amp;lt;textarea name=&amp;quot;tweet&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Send&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jsonparser.js&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e)){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			&lt;br /&gt;
		}&lt;br /&gt;
	})&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12107</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12107"/>
		<updated>2010-07-07T18:48:58Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict,javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; value=&amp;quot;username&amp;quot; id=&amp;quot;tweet&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;password&amp;quot; value=&amp;quot;password&amp;quot; id=&amp;quot;tweet&amp;quot;&amp;gt;	&lt;br /&gt;
	&amp;lt;textarea name=&amp;quot;tweet&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Send&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jsonparser.js&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e)){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			&lt;br /&gt;
		}&lt;br /&gt;
	})&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12106</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12106"/>
		<updated>2010-07-07T18:48:18Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;To save a few lines i&#039;ll be using the [http://www.jquery.com jQuery Framework]&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;&amp;quot; method=&amp;quot;get&amp;quot; accept-charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; value=&amp;quot;username&amp;quot; id=&amp;quot;tweet&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;password&amp;quot; value=&amp;quot;password&amp;quot; id=&amp;quot;tweet&amp;quot;&amp;gt;	&lt;br /&gt;
	&amp;lt;textarea name=&amp;quot;tweet&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Send&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jsonparser.js&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
	$(document).ready(function(){&lt;br /&gt;
		$(&#039;form&#039;).submit(function(e)){&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
			&lt;br /&gt;
		}&lt;br /&gt;
	})&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12105</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12105"/>
		<updated>2010-07-07T18:13:11Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12104</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12104"/>
		<updated>2010-07-07T18:10:29Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Print the tweets]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Serialize a form with JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
----&lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;14-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;br /&gt;
----&lt;br /&gt;
===Serialize a form with [[JavaScript]]===&lt;br /&gt;
&amp;lt;p&amp;gt;This is the part, where i want to show a few more things about JSON which is the JSON Parsers. JSON usually travels between web app and the server as a string, javascript has a really nice (and dangerous!) function which is &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;eval()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; this function reads string values and interprets it as javascript, which is quite convenient if the JSON file comes from a secure source, however we can&#039;t assure the security of an external service like twitter, so i&#039;m going to use a parser to convert the values of our form into a JSON, while i&#039;m also going to show the opposite, convert a JSON into a Javascript Object with the parser&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12102</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12102"/>
		<updated>2010-07-07T17:53:51Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry for writing this article in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
I&#039;m assuming that you are familiar with [[HTML]], [[CSS]], [[JavaScript]] and [[PHP]] for this article.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Print the tweets&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Serialize a form with [[JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The ability to use [http://curl.haxx.se/ cURL], is what allows us to interact with Twitter with the command-line, the same commands exist in PHP and we&#039;re using them right now to fetch the JSON. &lt;br /&gt;
===Print the Tweets===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; highlight=&amp;quot;13-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
	$resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the hightlighted area we decode the json into an array and then iterate and print the values of that array, with a little bit of CSS we can achieve something like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
[[File:Screen_shot_2010-07-07_at_7.24.39_PM.png]]&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:Screen_shot_2010-07-07_at_7.24.39_PM.png&amp;diff=12101</id>
		<title>File:Screen shot 2010-07-07 at 7.24.39 PM.png</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:Screen_shot_2010-07-07_at_7.24.39_PM.png&amp;diff=12101"/>
		<updated>2010-07-07T17:45:25Z</updated>

		<summary type="html">&lt;p&gt;Couto: List of tweets&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Descrição do ficheiro ==&lt;br /&gt;
List of tweets&lt;br /&gt;
== Copyright status: ==&lt;br /&gt;
&lt;br /&gt;
== Source: ==&lt;br /&gt;
http://cl.ly/1aqU&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12100</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12100"/>
		<updated>2010-07-07T17:30:47Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[#Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Print the tweets&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Serialize a form with [[JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
    $resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12099</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12099"/>
		<updated>2010-07-07T17:30:03Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[Get the JSON File with PHP and cURL]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Print the tweets&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Serialize a form with [[JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get the JSON with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
    $resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12098</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12098"/>
		<updated>2010-07-07T17:29:05Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[Get the JSON File with [[PHP]] and [[cURL]]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Print the tweets&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Serialize a form with [[JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Get the JSON File with [[PHP]] and [[cURL]]===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $user = &#039;username&#039;; &lt;br /&gt;
    $password = &#039;password&#039;; &lt;br /&gt;
     &lt;br /&gt;
    $ch = curl_init(&amp;quot;http://api.twitter.com/1/statuses/home_timeline.json?count=3&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
    curl_setopt($ch,CURLOPT_TIMEOUT, 30); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_USERPWD,$user . &amp;quot;:&amp;quot; . $password); &lt;br /&gt;
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); &lt;br /&gt;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); &lt;br /&gt;
    &lt;br /&gt;
	$result=curl_exec ($ch);&lt;br /&gt;
    $resultado = json_decode($result, true);&lt;br /&gt;
     &lt;br /&gt;
    foreach ($resultado as $value) {&lt;br /&gt;
        echo $value[&amp;quot;user&amp;quot;][&amp;quot;name&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;text&amp;quot;];&lt;br /&gt;
        echo $value[&amp;quot;created_at&amp;quot;];&lt;br /&gt;
    }&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12097</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12097"/>
		<updated>2010-07-07T17:17:54Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Get the JSON File with [[PHP]] and [[Curl]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Print the tweets&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Serialize a form with [[JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12096</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12096"/>
		<updated>2010-07-07T17:16:17Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
==Create a Small Twitter Client==&lt;br /&gt;
&amp;lt;p&amp;gt;Since it&#039;s so easy to use the Twitter&#039;s API, i&#039;m going to show here how to create a small twitter client. I&#039;m going to do some extra steps so that i can refer a few more things about JSON and Twitter&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;So the process i&#039;m going to use is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Get the JSON File with [[PHP]] and [[Curl]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Print the tweets&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Serialize a form with [[JavaScript]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Send the form to [[PHP]] with [[AJAX]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Post the tweet using a [http://dev.twitter.com/pages/libraries PHP Twitter Library]&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12095</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12095"/>
		<updated>2010-07-07T17:02:38Z</updated>

		<summary type="html">&lt;p&gt;Couto: /* Fetch and Include JSON File */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [http://web.uni-weimar.de/medien/wiki/JSON#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12094</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12094"/>
		<updated>2010-07-07T17:01:43Z</updated>

		<summary type="html">&lt;p&gt;Couto: /* Fetch and Include JSON File */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [#Twitter_API_Introduction Twitter API] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12093</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12093"/>
		<updated>2010-07-07T17:00:19Z</updated>

		<summary type="html">&lt;p&gt;Couto: /* Fetch and Include JSON File */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [[#Twitter_API_Introduction Twitter API]] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12092</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12092"/>
		<updated>2010-07-07T16:59:27Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pratical Examples with [[JavaScript]]==&lt;br /&gt;
===Fetch and Include JSON File===&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [[#Twitter%20API%20Introduction Twitter API]] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12091</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12091"/>
		<updated>2010-07-07T16:57:21Z</updated>

		<summary type="html">&lt;p&gt;Couto: /* Twitter API Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Pratical Examples with [[JavaScript]]&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Fetch and Include JSON File&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [[#Twitter API]] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API&#039;s, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12090</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12090"/>
		<updated>2010-07-07T16:55:29Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First of all, i&#039;m sorry or writing this tutorial in english, although i&#039;ve been around for a few months, i still don&#039;t feel comfortable enough to write in german.&lt;br /&gt;
&lt;br /&gt;
==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Pratical Examples with [[JavaScript]]&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Fetch and Include JSON File&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [[#Twitter API]] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12089</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12089"/>
		<updated>2010-07-07T16:52:27Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Pratical Examples with [[JavaScript]]&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Fetch and Include JSON File&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [[#Twitter API]] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
===Create a JSON Object===&lt;br /&gt;
So far we saw how to fetch and include an external JSON File and how to iterate and print a JSON object, but how do we create a JSON of our own? Since JSON was originally made from Javascript, to create an JSON all we need to do, it&#039;s to declare it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var jsonObject = {&lt;br /&gt;
	name: &#039;Luís&#039;,&lt;br /&gt;
	age: 23,&lt;br /&gt;
	student: true,&lt;br /&gt;
	hobbies: [&#039;Reading&#039;, &#039;Sleeping&#039;, &#039;Procrastinating&#039;],&lt;br /&gt;
	family_members: [&lt;br /&gt;
		{name: &amp;quot;Manuel&amp;quot;, age: 50, relation: &amp;quot;father&amp;quot;},&lt;br /&gt;
		{name: &amp;quot;Maria&amp;quot;, age: 47, relation &amp;quot;mother&amp;quot;}&lt;br /&gt;
	]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
alert(jsonObject.family_members[0].relation); //returns &amp;quot;father&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Pratical Examples with PHP==&lt;br /&gt;
===Create and Decode a JSON Object===&lt;br /&gt;
&amp;lt;p&amp;gt;[[PHP]] natively supports JSON which makes this process a no-effort task! So to create a JSON Object, we first define an array and populate it, then we encode the array to JSON:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$myTweet = array(&lt;br /&gt;
	&amp;quot;user&amp;quot; =&amp;gt;array(&lt;br /&gt;
		&amp;quot;id&amp;quot; =&amp;gt; 123456,&lt;br /&gt;
		&amp;quot;name&amp;quot; =&amp;gt; Username),&lt;br /&gt;
	&amp;quot;text&amp;quot; =&amp;gt; &amp;quot;I&#039;m going to be inside a JSON&amp;quot;,&lt;br /&gt;
	&amp;quot;created_at&amp;quot; =&amp;gt; &amp;quot;Wed Jul 07 18:12:12 +0000 2010&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$myJSONTweet = json_encode($myTweet);&lt;br /&gt;
&lt;br /&gt;
$myTweets = json_decode($myJSONTweet, true); //if true it will decode to an associative array&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_encode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; function actually takes care of the JSON syntax, and even makes the object &amp;lt;em&amp;gt;&amp;quot;user&amp;quot;&amp;lt;/em&amp;gt; inside the JSON. To decode it, we just use the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;json_decode()&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt; and the PHP will transform the JSON into an associative array, pretty much the opposite of the json_encode().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An &amp;lt;strong&amp;gt;API&amp;lt;/strong&amp;gt; (Application Programming Interface) it&#039;s a interface implemented by a service that allows programmers to interact with other software&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages, along with a response message, usually in a Markup Language (like [[XML]]) or JSON, other formats that are also quite common are RSS and ATOM&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The use of API, allowed web services to share content and create an open sharing arquitecture. A common example it&#039;s the video embedding through [http://www.youtube.com YouTube] or [http://www.vimeo.com Vimeo]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;p&amp;gt;Among several things, i believe that these three are essential to use the Twitter&#039;s API:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The API is entirely HTTP-based&lt;br /&gt;
&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Where methods to retrieve data use the GET request.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;publishing, modifying or destroying data on Twitter requires the POST request.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A command-line is all you need to interact with the Twitter API&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;There are [http://dev.twitter.com/pages/libraries Twitter API libraries] for almost any language&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12079</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12079"/>
		<updated>2010-07-07T15:59:14Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Pratical Examples with [[JavaScript]]&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Fetch and Include JSON File&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [[#Twitter API]] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
==Twitter API Introduction==&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://twitter.com/about&amp;quot;&amp;gt;&amp;quot;Twitter is a real-time information network powered by people all around the world that lets you share and discover what’s happening now.&lt;br /&gt;
Twitter asks “what’s happening” and makes the answer spread across the globe to millions, immediately.&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://twitter.com/about Twitter About Us page]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote cite=&amp;quot;http://www.slideshare.net/padday/the-real-life-social-network-v2&amp;quot;&amp;gt;The social web is not a fad, and itʼs not going away. Itʼs not an add-on to the web as we know it today. Itʼs a fundamental change, a re-architecture, and in hindsight its evolution is obvious.&lt;br /&gt;
Make no mistake about this. Everyone in this room will need to learn how to design social features on websites. Whether you like it or not&amp;lt;br /&amp;gt;&amp;lt;em&amp;gt;in [http://www.slideshare.net/padday/the-real-life-social-network-v2 Paul Adams in The Real Social Network]&amp;lt;/em&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;My choice of using the Twitter API, is due to two reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s relatively easy, and pretty straightforward to use&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;It&#039;s well documented&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
===What you need to know===&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12078</id>
		<title>JSON</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=JSON&amp;diff=12078"/>
		<updated>2010-07-07T15:31:02Z</updated>

		<summary type="html">&lt;p&gt;Couto: Created page with &amp;#039;==  JSON Introduction ==  &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for JavaScript Object Notation) is a data interchange format, designed for human-readability. It&amp;#039;s lightweight, te…&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==  JSON Introduction ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;JSON&amp;lt;/strong&amp;gt; (acronym for [[JavaScript]] Object Notation) is a data interchange format, designed for human-readability. It&#039;s lightweight, text-based, open standard and usually serves as an alternative to [[XML]] to transmit data over a network or between a server and a web application.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;JSON was a subset of the [[JavaScript]] programming language, but despite its relationship, it&#039;s considered to be language-independent, with [http://www.json.org parsers available for almost every language].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JSON Data Types, Syntax and Structure ==&lt;br /&gt;
&lt;br /&gt;
===JSON Data Types:===&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Number&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;Either as &amp;lt;em&amp;gt;Integer&amp;lt;/em&amp;gt;: (…,-1,0,1,…) or as &amp;lt;em&amp;gt;Real&amp;lt;/em&amp;gt;: (3,141592…)&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;String&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;double-quoted Unicode: &amp;quot;Jonh Doe&amp;quot;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Boolean&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;true&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;false&amp;lt;/em&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Array&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;an ordered sequence of values, comma-separated and enclosed in square brackets &amp;lt;em&amp;gt;[ ]&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;[&amp;quot;Value1&amp;quot;,&amp;quot;Value2&amp;quot;,&amp;quot;Value2&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Object&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;a collection of key:value pairs, comma-separated and enclosed in curly braces &amp;lt;em&amp;gt; { }&amp;lt;/em&amp;gt;: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;{&amp;quot;Key1&amp;quot;:&amp;quot;Value1&amp;quot; , &amp;quot;Key2&amp;quot;:&amp;quot;Value2&amp;quot; , &amp;quot;Key3&amp;quot;:&amp;quot;Value3&amp;quot;}&amp;lt;/source&amp;gt;&lt;br /&gt;
	&amp;lt;dt&amp;gt;&amp;lt;strong&amp;gt;Null Value&amp;lt;/strong&amp;gt;&lt;br /&gt;
	&amp;lt;dd&amp;gt;&amp;lt;em&amp;gt;null&amp;lt;/em&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===JSON Syntax and Structure===&lt;br /&gt;
&amp;lt;p&amp;gt;A typical JSON file could be presented like this:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; &amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;firstName&amp;quot;: &amp;quot;John&amp;quot;, 						//String&lt;br /&gt;
	&amp;quot;lastName&amp;quot;: &amp;quot;Doe&amp;quot;,&lt;br /&gt;
	&amp;quot;age&amp;quot;: 39,  							//Number&lt;br /&gt;
	&amp;quot;has_kids&amp;quot;: false,  						//Boolean&lt;br /&gt;
	&amp;quot;Hobbies&amp;quot;:[&amp;quot;Reading&amp;quot;,&amp;quot;Skating&amp;quot;,&amp;quot;Music&amp;quot;]				//Array&lt;br /&gt;
	&amp;quot;address&amp;quot;: { 							//Object&lt;br /&gt;
		&amp;quot;streetAddress&amp;quot;: &amp;quot;Somewhere over the rainbow 2-1&amp;quot;,&lt;br /&gt;
		&amp;quot;city&amp;quot;: &amp;quot;New York&amp;quot;,&lt;br /&gt;
		&amp;quot;postalCode&amp;quot;: 10021&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;phoneNumber&amp;quot;: [						//Array and Object&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;home&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: 2125551234 },&lt;br /&gt;
		{ &amp;quot;type&amp;quot;: &amp;quot;fax&amp;quot;, &lt;br /&gt;
		  &amp;quot;number&amp;quot;: null					//null value &lt;br /&gt;
		}],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;sub&amp;gt;However, like Javascript, JSON can be formatted to be single-line.&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Pratical Examples with [[JavaScript]]&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt;Fetch and Include JSON File&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;I will show now, how to use [[JavaScript]] to print JSON files on a [[HTML]] page. I will use the [[#Twitter API]] to get a JSON file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://twitter.com/statuses/public_timeline.json http://twitter.com/statuses/public_timeline.json] this link allow us to download a JSON file with the last 20 public tweets on [http://www.twitter.com Twitter]. Due security reasons [http://en.wikipedia.org/wiki/Cross-site_scripting (XSS)], we can not fetch the file with using XmlHttpRequest ([[AJAX]]) directly as so, we include it directly in the HTML page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot; highlight=&amp;quot;9,10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Print the JSON values&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Notice the &amp;lt;em&amp;gt;&amp;lt;strong&amp;gt;?callback=public_timeline&amp;lt;/strong&amp;gt;&amp;lt;/em&amp;gt;? We&#039;re using it, because if we download the file directly, we won&#039;t be able to use it sincee it&#039;s not assigned to any variable, or object or any other kind of javascript resource, so the [http://dev.twitter.com/ Twitter API] allow us to call the file with a [http://dev.twitter.com/pages/every_developer callback function] and so making the file usable for manipulation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;We now have the JSON file with a callback function to make it usable. We print its values by adding the following script: &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot; highlight=&amp;quot;11-20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE HTML&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
	&amp;lt;head&amp;gt;&lt;br /&gt;
		&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=UTF-8&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;title&amp;gt;Your Website&amp;lt;/title&amp;gt;&lt;br /&gt;
	&amp;lt;/head&amp;gt;&lt;br /&gt;
	&amp;lt;body&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://twitter.com/statuses/public_timeline.json?&lt;br /&gt;
callback=public_timeline&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
		var tweet;&lt;br /&gt;
		function public_timeline(data){&lt;br /&gt;
			tweet = data;&lt;br /&gt;
			for(var i in tweet){&lt;br /&gt;
				document.write(tweet[i].user.name);&lt;br /&gt;
				document.write(tweet[i].text);&lt;br /&gt;
				document.write(tweet[i].created_at);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	&amp;lt;/script&amp;gt;&lt;br /&gt;
	&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Because JSON is natively Javascript we don&#039;t need to parse it, in this particular example, and we can itinerate it&#039;s values directly using the dot syntax.&amp;lt;/p&amp;gt;&lt;br /&gt;
==Twitter==&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=IFD:Netz&amp;diff=12075</id>
		<title>IFD:Netz</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=IFD:Netz&amp;diff=12075"/>
		<updated>2010-07-07T12:43:55Z</updated>

		<summary type="html">&lt;p&gt;Couto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Netzwerk_zentral.jpg|right|300px]]&lt;br /&gt;
Bachelor-Werkmodul &amp;lt;br/&amp;gt;&lt;br /&gt;
&#039;&#039;Lehrperson:&#039;&#039; [[Michael Markert]]&amp;lt;br/&amp;gt;&lt;br /&gt;
&#039;&#039;Bewertung:&#039;&#039; 6 [[ECTS]], 2 [[SWS]]&amp;lt;br/&amp;gt;&lt;br /&gt;
&#039;&#039;Termin:&#039;&#039; Mittwochs, 11-12.30 Uhr&#039;&#039;&#039;&amp;lt;br/&amp;gt;&lt;br /&gt;
&#039;&#039;Ort:&#039;&#039; [[Marienstraße 7b]], Projektraum 104&amp;lt;br/&amp;gt;&lt;br /&gt;
&#039;&#039;Erster Termin:&#039;&#039; 14.04.2010, 11 Uhr&amp;lt;br/&amp;gt;&lt;br /&gt;
Der genaue Termin/Ort wird mit der Bestätigung der Anmeldung per E-Mail mitgeteilt!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das Werkmodul richtet sich an Studierende aller Fachrichtungen mit Vorkenntnissen im Bereich Webdesign (HTML, CSS), die an experimenteller Netzkunst oder der Entwicklung von interaktiven Web-Anwendungen und User-Interfaces interessiert sind. &lt;br /&gt;
&lt;br /&gt;
Der Fokus liegt auf fortgeschrittenen Webtechnologien wie z.B. PHP und JavaScript, Processing Applets bzw. der Kombination verschiedener Techniken. Auch auf die Einbindung von Hardware wie z.B. Sensoren und Aktuatoren von Mobiltelefonen oder Mikrocontrollern (z.B. Arduinos mit LAN-Schnittstelle) kann eingegangen werden. &lt;br /&gt;
&lt;br /&gt;
Die endgültigen Themen des Kurses orientieren sich an den Erfordernissen der einzelnen Projekte. Das Werkmodul ist nicht als Frontalunterricht konzipiert, sondern versteht sich als Arbeitsgruppe, in der Ideen, Technologien und Techniken vorgestellt und diskutiert werden.&lt;br /&gt;
&lt;br /&gt;
Dieser Kurs kann auch in Kombination mit (oder alternativ zu) dem Werkmodul [[IFD:iPhone-Dev|iPhone Development]] belegt werden, um Webapplikationen für mobile Endgeräte zu erstellen. Eine Kombination mit Projektaufgaben (wie z.B. dem Bachelor Projekt der Professur Inteface-Design [[IFD:PodPhonePad_and_Me|Interface Design 2 / Interaktion mit mobilen Medien]] oder dem [[GMU:Netze|Netzwelten-Ausstellungsprojekt der Professur Gestaltung medialer Umgebungen]]) ist ausdrücklich erwünscht.&lt;br /&gt;
&lt;br /&gt;
== Themen ==&lt;br /&gt;
* Auffrischung [[HTML]] und [[CSS]]&lt;br /&gt;
* Neue [http://www.w3schools.com/html5/html5_reference.asp HTML5]-Features: What&#039;s hot, what not&lt;br /&gt;
* [[Netzstrukturen]] (Zentrale, dezentrale, verteilte Netzwerke…)&lt;br /&gt;
* [[OSC]], [[TCP/IP UDP|TCP/IP und UDP]], Local Horst und Co., Inter-Application Communication&lt;br /&gt;
* [[JavaScript]] und einschlägige JS-Libraries (JQuery, Scriptaculous)&lt;br /&gt;
* [[AJAX]]&lt;br /&gt;
* [[PHP]], GD-Library, PHPThumb&lt;br /&gt;
* [[Processing]] und [[JAVA]]&lt;br /&gt;
* [[Arduino]] und [[Mobile Processing]]&lt;br /&gt;
* [[OOP]], [[MVC]]&lt;br /&gt;
* [[Informationsethik]]&lt;br /&gt;
* Einführung in [[Systemtheorie|kybernetische Systemtheorie]]&lt;br /&gt;
&lt;br /&gt;
== Voraussetzungen ==&lt;br /&gt;
* Vorkenntnisse in einer Programmiersprache&lt;br /&gt;
* oder sehr gute Kenntnisse in HTML/CSS&lt;br /&gt;
&lt;br /&gt;
Bei Fragen zum Kurs kontaktieren Sie mich bitte per eMail!&lt;br /&gt;
&lt;br /&gt;
{{Template:Anmeldung_MM}}&lt;br /&gt;
&lt;br /&gt;
== Leistungsnachweis ==&lt;br /&gt;
* 33% regelmäßige und aktive Teilnahme&lt;br /&gt;
* 33% Kurzreferat (als Diskussionsstarter, max. 45 min.)&lt;br /&gt;
* 33% Einreichung einer teilweise oder ganz umgesetzen Projektidee (idealerweise mit begleitender und abschließender Dokumentation im Wiki). Die Abgabe erfolgt mit einem kurzen individuellen Gespräch, in dem mir jeder Teilnehmer eine Note vorschlägt und begründet&lt;br /&gt;
* 15% Wiki-Bonus: für neue Artikel bzw. Ergänzungen im Wiki&lt;br /&gt;
&lt;br /&gt;
== Zielgruppe ==&lt;br /&gt;
Das Werkmodul richtet sich an Studierende aller Fachrichtungen mit Vorkenntnissen im Bereich Webdesign (HTML, CSS), die an experimenteller Netzkunst oder der Entwicklung von interaktiven Web-Anwendungen und User-Interfaces interessiert sind. &lt;br /&gt;
&lt;br /&gt;
== Projekte ==&lt;br /&gt;
Laufende Dokumentation der Kursprojekte:&lt;br /&gt;
* [[IFD:Netzprojekte]]&lt;br /&gt;
&lt;br /&gt;
== Terminplan ==&lt;br /&gt;
Vorläufiger Terminplan&lt;br /&gt;
# 14.04. Einführung&lt;br /&gt;
# 21.04. Recap [[HTML]], [[CSS]], [http://code.google.com/p/zen-coding/ Zen-Coding] (Michael)&lt;br /&gt;
# 28.04. [[Netzstrukturen]], [[TCP/IP UDP|TCP/IP, UDP]], [[OSC]], inter-application communication: lokal und global (Michael)&lt;br /&gt;
# 05.05. PHP, [[Regular Expressions]] (Moritz)&lt;br /&gt;
# 12.05. [[JSON]]: JavaScript Object Notation, APIs: Twitter (Luís)&lt;br /&gt;
# 19.05. XML (Daniel)&lt;br /&gt;
# 26.05. OOP-JavaScript/Python (Christian), AJAX (Moritz)&lt;br /&gt;
# 02.06. jQuery, Canvas (Gabriel)&lt;br /&gt;
# 09.06. [[HTML#HTML5|HTML5]] (Jan)&lt;br /&gt;
# 16.06. Entwicklerverantwortung (Moritz)&lt;br /&gt;
# 23.06. * (Pauline), * (Alexander)&lt;br /&gt;
# 30.06. Hardware: Arduino (Sebastian), (Michael)&lt;br /&gt;
# 07.07. Letzte Stunde: Recap, Questions, What&#039;s really important&amp;lt;br/&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
# 14.07. Ausstellungsvorbereitung gelungener Arbeiten für Summary am 15.07.&lt;br /&gt;
# 29.09. Abgabe&lt;br /&gt;
&lt;br /&gt;
Abgabe der Ergebnisse als Dokumentation im Wiki mit Screenshots und Erläuterungen, evtl. kompilierbare quelloffene Projektdatei, bis zum 29.09.2010.&lt;br /&gt;
&lt;br /&gt;
== Literatur ==&lt;br /&gt;
t.b.a.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* Linksammlung [[Netzkunst]]&lt;br /&gt;
* Lecture Notes des Moduls [http://www.uni-weimar.de/cms/medien/webis/teaching/lecture-notes.html Web Technology &amp;amp; Information Systems] bei Prof. Benno Stein (Uni Weimar)&lt;br /&gt;
&lt;br /&gt;
{{Template:Netzkurs}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Arduino]]&lt;br /&gt;
[[Category:Processing]]&lt;br /&gt;
[[Category:Interaktion]]&lt;br /&gt;
[[Category:SS10]]&lt;/div&gt;</summary>
		<author><name>Couto</name></author>
	</entry>
</feed>