SlideShare a Scribd company logo
1 of 43
Introduction to JSON JavaScript Object Notations Raghavendra Nayak M
Created by RaghavendraNayak M	 All sample codes in this slide are released under Public Domain. Contact me at http://twitter.com/MRNayak rnayak@hotmail.com Raghavendra Nayak M
What we will learn today? Basics of HTML Basics of JavaScript JSON Building YouTube App  Twitter App  Wikipedia App Raghavendra Nayak M
Why JSON? JSON is an alternative to XML Using JSON we can build various 3rd party applications. It is easy to retrieve Tweets, YouTube Videos and many more using JSON. Programming is simple and easy. JSON data is easy to read. JSON parsers are available in various JavaScript Framework like jQuery, Yahoo UI Raghavendra Nayak M
Basics about HTML ,[object Object]
It is a markup language and not a programming language.
Markup language is set of various tags.
It uses markup language to describe a page.
A web page with .php, .py, .rb is a dynamically generated HTML page using backend languages.Raghavendra Nayak M
Simple HTML Page  <html> <head> <title>Hello Everyone</title> <link rel="stylesheet" type="text/css" href="style.css" > </link> </head><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>  Raghavendra Nayak M
HTML Heading Tag <h1>-<h6> Heading tags in HTML are defined from <h1> to <h6> <h1> Hello Everyone </h1> <h2> Hello Everyone </h1> …. … <h6> Hello Everyone </h6> Raghavendra Nayak M
Paragraph Tag	 In HTML paragraphs are defined using <p> tag. <p> Hello </p> <p> A quick brown fox jumped over a lazy village dog.</p> Raghavendra Nayak M
Break Tag	 <br> tag in HTML adds a single line break. If we want content to appear in new line then we must use break tag. Raghavendra Nayak M
Anchor Tag	 In HTML we use <a> tag (Anchor Tag) to create links <a href=“http://www.google.com”>Google</a> Here href contains the link to another document. We can also call JavaScript functions using anchor tag. <a href=“#” onclick=“smefunc();”> Click Me</a>  Raghavendra Nayak M
Image Tag We use <img> tag to embed images in a webpage. <imgsrc=“a.jpg”></img> Above tag will embed a image a.jpg. We can use images for creating links. <a href=“http://www.google.com” ><imgsrc=“a.png”/></a> We can specify height and width of image <imgsrc=“a.jpg” width=“200px” height=“100px”   alt=“goog”/> Raghavendra Nayak M
Division Tag A division tag or div tag (<div>) is used to create division in HTML <div id=“one” class=“three”> id specify unique id for element. class specify class name for an element.  There can be two or more elements with same class name. Raghavendra Nayak M
Link Tag	 Link Tag specifies link between existing document and external resources <link rel="stylesheet" type="text/css" href=“style.css" /> We use link to specify external stylesheet. Raghavendra Nayak M
Script Tag Script tag is used to include client side scripts like JavaScript. <script type=“text/javascript”>alert(‘Msg”);</script> Script tag can also contain external scripts. <script type=“text/javascript” src=“hme.js” /> Raghavendra Nayak M
Basics of Javascript JavaScript is a client side Scripting Language. It helps to add dynamic effect to web pages. JavaScript can be used to create image sliders, charts, AJAX Applications and many more. JavaScripts are used as event handlers. JavaScript are used to create and read cookie. Various Javascript Frameworks like jQuery, MooTools, YUI make programming even more easier. Raghavendra Nayak M
Variables in Javascript In JavaScript we define Variables using ‘var’ <script type=“text/javascript”> var a=10;//Integer var b=‘Hello’;//Char alert(b);//a dialogbox with contents of variable b // Single line comment /* Multiline Comment */ </script> Raghavendra Nayak M
Getting Client Side Date Its is possible to get users date, browser, os etc using JavaScript <script type=“text/javascript”> var d=new Date(); alert(d); </script> Raghavendra Nayak M
Printing Variables in JS Just like printf in C, In JavaScript we use document.write(); <script type=“text/javascript”> document.write(“Hello Everyone”); </script> <script type=“text/javascript”> var a=‘Hello World’; document.write(a); </script> Raghavendra Nayak M
+ operator in JavaScript + operator is used to add integers. + operator is used to concatenate to strings <script type=“text/javascript”> var a=2; var b=3; document.write(a+b); var c=‘Hello’; var d=‘everyone’;  document.write(c+d); </script> Raghavendra Nayak M
JS and C Syntax of if…else , for loop , while loop in JavaScript are same as that of C. if(i==0) { for(j=0;j<n;j++) { //sme code } else alert(‘i !=0’); Raghavendra Nayak M
Arrays in JavaScript Array is used to store multiple values in single variable. <script type=“text/javascript”> var dept=new Array(4); dept[0]=‘CSE’; dept[1]=‘ISE’; dept[2]=‘ECE’; dept[4]=‘ME’; for(vari=0;i<dept.length;i++) document.write(dept[i]); </script> Raghavendra Nayak M
Problems with array It is difficult to handle large volume of data using Arrays. This problem can be solved by using JSON Raghavendra Nayak M
JSON JSON is a human readable data interchange. It is derived from JavaScript, But it is language independent. JSON supports strings, numbers, objects, arrays and Boolean It is primarily used to send data from web server to application. There are inbuilt functions and libraries to parse JSON in many languages. Raghavendra Nayak M
Simple JSON Format {  "id": 1,  "name": “Raghavendra",  “dept": “CSE”,  }  JSON starts with ‘{‘ and ends with ‘}’ JSON has a optional callback myJSON({“id”:1,”name”:”Raghavendra”,”dept”:”CSE”});  Raghavendra Nayak M
Simple C Program #include<stdio.h> void p(char a[]) { printf(“%s”,a); } void main() { char ab[4]={‘H’,’E’,’L’,’L’,’O’}; p(ab); } When we run above program, it will print HELLO, Similarly we build a json parser and then call parsing function with JSON as an argument. Raghavendra Nayak M
Parsing JSON using JS {"students": [ { "name":"Rahul", "usn":"cs066" }, { "name":"Rajiv", "usn":"cs068" }, { "name":"Rudresh", "usn":"cs072" }, ] } Raghavendra Nayak M
Js Code for parsing If we specify a callback to above student json and if call back url is MyJson then MyJson({"students":[{"name":"Rahul","usn":"cs066"},{"name":"Rajiv","usn":"cs068"},{"name":"Rudresh","usn":"cs072"}]}); Raghavendra Nayak M
Writing MyJson Function <script type=“text/javascript”> Function MyJson(data) { For(vari=0;i<data.student.length;i++) { var  name=data.student[i].name; varusn=data.student[i].usn; document.write(usn+” “+name); } } </script> Raghavendra Nayak M
Complete Code <script type=“text/javascript”> function MyJson(data) { For(vari=0;i<data.student.length;i++) { var  name=data.student[i].name; varusn=data.student[i].usn; document.write(usn+” “+name); } } </script> <script type=“text/javascript” src=“student.json?callback=MyJson”></script> Raghavendra Nayak M
Building A Simple YouTube App YouTube is a video hosting service from Google. YouTube Provides various API’s to access its data It offers data in XML, JSONC format Raghavendra Nayak M
Youtube JSON Example Constructing URL Base URL is http://gdata.youtube.com/feeds/api/videos?v=2 Parameters q=<search query> callback=<function name> http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=eminem&callback=myvideo The first parameter to url should begin with ‘?’ and all other parameter should begin with ‘&’ Raghavendra Nayak M
MyVideo Function <script type="text/javascript">function myvideo(json)  {    for(i=0;i<6;i++)    {      var title=json.data.items[i].title;      document.write(title+'<br/>');    }  }</script> <script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=eminem&callback=myvideo"></script> Raghavendra Nayak M
Embedding YouTube Video YouTube Videos are Abobe flash content we can embed them using <embed src=“FLASH URL” width=“300px” height=“200px”></embed> Raghavendra Nayak M
Full Source Code <script type="text/javascript">function myvideo(json)  {    for(i=0;i<6;i++)    {      var title=json.data.items[i].title;      var video='<embed src="'+json.data.items[i].content[5]+'"/>';      document.write(title+'<br/>'+video+'</br>');    }  }</script><script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=eminem&callback=myvideo"></script> Raghavendra Nayak M
Wikipedia API Wikipedia is a free encyclopedia which anyone can edit. Wikipedia uses a CMS(Content Management System) know as Media Wiki. We can perform use wikipedia suggest api, pages api and many more things Raghavendra Nayak M
URL Construction Base URL is http://en.wikipedia.org/w/api.php Parameters action=parse page=<Page Name> prop=text format=json callback=mywiki(callback function) Raghavendra Nayak M
MyWiki Function <script type="text/javascript">function mywiki(json)            {           	var html=[ ];        	varind = json.parse.text.*;        	html.push(ind);       		document.write(html);            } </script> Above function helps us to retrieve a wikipedia page. Raghavendra Nayak M
Complete Source Code <script type="text/javascript">      function mywiki(json)            {    			    var html=[ ];    			    varind = json.parse.text.*;    			    html.push(ind);      			 document.write(html);            }  </script>  <script type="text/javascript" src="http://en.wikipedia.org/w/api.php?action=parse&page=Bangalore&prop=text&format=json&callback=mywiki"></script>  Raghavendra Nayak M
Twitter Public Timeline Twitter is a micro blogging site. A list of Public Tweets is called as Public Timeline. Public Timeline doesn’t require Authentication to retrieve tweets. Raghavendra Nayak M

More Related Content

Similar to Introduction to JSON and Building Youtube, Twitter and Wikipedia Web Apps

ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Matteo Collina
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone InteractivityEric Steele
 
What I brought back from Austin
What I brought back from AustinWhat I brought back from Austin
What I brought back from AustinLisa Adkins
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesJohn Brunswick
 
Microformats HTML to API
Microformats HTML to APIMicroformats HTML to API
Microformats HTML to APIelliando dias
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp ArchitectureMorgan Cheng
 
Javascript
JavascriptJavascript
JavascriptIblesoft
 
Real-World AJAX with ASP.NET
Real-World AJAX with ASP.NETReal-World AJAX with ASP.NET
Real-World AJAX with ASP.NETgoodfriday
 
Introduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsIntroduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsJohannes Geppert
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 

Similar to Introduction to JSON and Building Youtube, Twitter and Wikipedia Web Apps (20)

Javascript
JavascriptJavascript
Javascript
 
Grails and Dojo
Grails and DojoGrails and Dojo
Grails and Dojo
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Jsp
JspJsp
Jsp
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
What I brought back from Austin
What I brought back from AustinWhat I brought back from Austin
What I brought back from Austin
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
 
Microformats HTML to API
Microformats HTML to APIMicroformats HTML to API
Microformats HTML to API
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
 
J s-o-n-120219575328402-3
J s-o-n-120219575328402-3J s-o-n-120219575328402-3
J s-o-n-120219575328402-3
 
Javascript
JavascriptJavascript
Javascript
 
Merb jQuery
Merb jQueryMerb jQuery
Merb jQuery
 
Ajax
AjaxAjax
Ajax
 
Real-World AJAX with ASP.NET
Real-World AJAX with ASP.NETReal-World AJAX with ASP.NET
Real-World AJAX with ASP.NET
 
Gwt Presentation
Gwt PresentationGwt Presentation
Gwt Presentation
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
Introduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsIntroduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid Tags
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 

Recently uploaded

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Recently uploaded (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Introduction to JSON and Building Youtube, Twitter and Wikipedia Web Apps

  • 1. Introduction to JSON JavaScript Object Notations Raghavendra Nayak M
  • 2. Created by RaghavendraNayak M All sample codes in this slide are released under Public Domain. Contact me at http://twitter.com/MRNayak rnayak@hotmail.com Raghavendra Nayak M
  • 3. What we will learn today? Basics of HTML Basics of JavaScript JSON Building YouTube App Twitter App Wikipedia App Raghavendra Nayak M
  • 4. Why JSON? JSON is an alternative to XML Using JSON we can build various 3rd party applications. It is easy to retrieve Tweets, YouTube Videos and many more using JSON. Programming is simple and easy. JSON data is easy to read. JSON parsers are available in various JavaScript Framework like jQuery, Yahoo UI Raghavendra Nayak M
  • 5.
  • 6. It is a markup language and not a programming language.
  • 7. Markup language is set of various tags.
  • 8. It uses markup language to describe a page.
  • 9. A web page with .php, .py, .rb is a dynamically generated HTML page using backend languages.Raghavendra Nayak M
  • 10. Simple HTML Page <html> <head> <title>Hello Everyone</title> <link rel="stylesheet" type="text/css" href="style.css" > </link> </head><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html> Raghavendra Nayak M
  • 11. HTML Heading Tag <h1>-<h6> Heading tags in HTML are defined from <h1> to <h6> <h1> Hello Everyone </h1> <h2> Hello Everyone </h1> …. … <h6> Hello Everyone </h6> Raghavendra Nayak M
  • 12. Paragraph Tag In HTML paragraphs are defined using <p> tag. <p> Hello </p> <p> A quick brown fox jumped over a lazy village dog.</p> Raghavendra Nayak M
  • 13. Break Tag <br> tag in HTML adds a single line break. If we want content to appear in new line then we must use break tag. Raghavendra Nayak M
  • 14. Anchor Tag In HTML we use <a> tag (Anchor Tag) to create links <a href=“http://www.google.com”>Google</a> Here href contains the link to another document. We can also call JavaScript functions using anchor tag. <a href=“#” onclick=“smefunc();”> Click Me</a> Raghavendra Nayak M
  • 15. Image Tag We use <img> tag to embed images in a webpage. <imgsrc=“a.jpg”></img> Above tag will embed a image a.jpg. We can use images for creating links. <a href=“http://www.google.com” ><imgsrc=“a.png”/></a> We can specify height and width of image <imgsrc=“a.jpg” width=“200px” height=“100px” alt=“goog”/> Raghavendra Nayak M
  • 16. Division Tag A division tag or div tag (<div>) is used to create division in HTML <div id=“one” class=“three”> id specify unique id for element. class specify class name for an element. There can be two or more elements with same class name. Raghavendra Nayak M
  • 17. Link Tag Link Tag specifies link between existing document and external resources <link rel="stylesheet" type="text/css" href=“style.css" /> We use link to specify external stylesheet. Raghavendra Nayak M
  • 18. Script Tag Script tag is used to include client side scripts like JavaScript. <script type=“text/javascript”>alert(‘Msg”);</script> Script tag can also contain external scripts. <script type=“text/javascript” src=“hme.js” /> Raghavendra Nayak M
  • 19. Basics of Javascript JavaScript is a client side Scripting Language. It helps to add dynamic effect to web pages. JavaScript can be used to create image sliders, charts, AJAX Applications and many more. JavaScripts are used as event handlers. JavaScript are used to create and read cookie. Various Javascript Frameworks like jQuery, MooTools, YUI make programming even more easier. Raghavendra Nayak M
  • 20. Variables in Javascript In JavaScript we define Variables using ‘var’ <script type=“text/javascript”> var a=10;//Integer var b=‘Hello’;//Char alert(b);//a dialogbox with contents of variable b // Single line comment /* Multiline Comment */ </script> Raghavendra Nayak M
  • 21. Getting Client Side Date Its is possible to get users date, browser, os etc using JavaScript <script type=“text/javascript”> var d=new Date(); alert(d); </script> Raghavendra Nayak M
  • 22. Printing Variables in JS Just like printf in C, In JavaScript we use document.write(); <script type=“text/javascript”> document.write(“Hello Everyone”); </script> <script type=“text/javascript”> var a=‘Hello World’; document.write(a); </script> Raghavendra Nayak M
  • 23. + operator in JavaScript + operator is used to add integers. + operator is used to concatenate to strings <script type=“text/javascript”> var a=2; var b=3; document.write(a+b); var c=‘Hello’; var d=‘everyone’; document.write(c+d); </script> Raghavendra Nayak M
  • 24. JS and C Syntax of if…else , for loop , while loop in JavaScript are same as that of C. if(i==0) { for(j=0;j<n;j++) { //sme code } else alert(‘i !=0’); Raghavendra Nayak M
  • 25. Arrays in JavaScript Array is used to store multiple values in single variable. <script type=“text/javascript”> var dept=new Array(4); dept[0]=‘CSE’; dept[1]=‘ISE’; dept[2]=‘ECE’; dept[4]=‘ME’; for(vari=0;i<dept.length;i++) document.write(dept[i]); </script> Raghavendra Nayak M
  • 26. Problems with array It is difficult to handle large volume of data using Arrays. This problem can be solved by using JSON Raghavendra Nayak M
  • 27. JSON JSON is a human readable data interchange. It is derived from JavaScript, But it is language independent. JSON supports strings, numbers, objects, arrays and Boolean It is primarily used to send data from web server to application. There are inbuilt functions and libraries to parse JSON in many languages. Raghavendra Nayak M
  • 28. Simple JSON Format { "id": 1, "name": “Raghavendra", “dept": “CSE”, } JSON starts with ‘{‘ and ends with ‘}’ JSON has a optional callback myJSON({“id”:1,”name”:”Raghavendra”,”dept”:”CSE”}); Raghavendra Nayak M
  • 29. Simple C Program #include<stdio.h> void p(char a[]) { printf(“%s”,a); } void main() { char ab[4]={‘H’,’E’,’L’,’L’,’O’}; p(ab); } When we run above program, it will print HELLO, Similarly we build a json parser and then call parsing function with JSON as an argument. Raghavendra Nayak M
  • 30. Parsing JSON using JS {"students": [ { "name":"Rahul", "usn":"cs066" }, { "name":"Rajiv", "usn":"cs068" }, { "name":"Rudresh", "usn":"cs072" }, ] } Raghavendra Nayak M
  • 31. Js Code for parsing If we specify a callback to above student json and if call back url is MyJson then MyJson({"students":[{"name":"Rahul","usn":"cs066"},{"name":"Rajiv","usn":"cs068"},{"name":"Rudresh","usn":"cs072"}]}); Raghavendra Nayak M
  • 32. Writing MyJson Function <script type=“text/javascript”> Function MyJson(data) { For(vari=0;i<data.student.length;i++) { var name=data.student[i].name; varusn=data.student[i].usn; document.write(usn+” “+name); } } </script> Raghavendra Nayak M
  • 33. Complete Code <script type=“text/javascript”> function MyJson(data) { For(vari=0;i<data.student.length;i++) { var name=data.student[i].name; varusn=data.student[i].usn; document.write(usn+” “+name); } } </script> <script type=“text/javascript” src=“student.json?callback=MyJson”></script> Raghavendra Nayak M
  • 34. Building A Simple YouTube App YouTube is a video hosting service from Google. YouTube Provides various API’s to access its data It offers data in XML, JSONC format Raghavendra Nayak M
  • 35. Youtube JSON Example Constructing URL Base URL is http://gdata.youtube.com/feeds/api/videos?v=2 Parameters q=<search query> callback=<function name> http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=eminem&callback=myvideo The first parameter to url should begin with ‘?’ and all other parameter should begin with ‘&’ Raghavendra Nayak M
  • 36. MyVideo Function <script type="text/javascript">function myvideo(json)  {    for(i=0;i<6;i++)    {      var title=json.data.items[i].title;      document.write(title+'<br/>');    }  }</script> <script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=eminem&callback=myvideo"></script> Raghavendra Nayak M
  • 37. Embedding YouTube Video YouTube Videos are Abobe flash content we can embed them using <embed src=“FLASH URL” width=“300px” height=“200px”></embed> Raghavendra Nayak M
  • 38. Full Source Code <script type="text/javascript">function myvideo(json)  {    for(i=0;i<6;i++)    {      var title=json.data.items[i].title;      var video='<embed src="'+json.data.items[i].content[5]+'"/>';      document.write(title+'<br/>'+video+'</br>');    }  }</script><script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=eminem&callback=myvideo"></script> Raghavendra Nayak M
  • 39. Wikipedia API Wikipedia is a free encyclopedia which anyone can edit. Wikipedia uses a CMS(Content Management System) know as Media Wiki. We can perform use wikipedia suggest api, pages api and many more things Raghavendra Nayak M
  • 40. URL Construction Base URL is http://en.wikipedia.org/w/api.php Parameters action=parse page=<Page Name> prop=text format=json callback=mywiki(callback function) Raghavendra Nayak M
  • 41. MyWiki Function <script type="text/javascript">function mywiki(json)            {        var html=[ ];         varind = json.parse.text.*;        html.push(ind);        document.write(html);            } </script> Above function helps us to retrieve a wikipedia page. Raghavendra Nayak M
  • 42. Complete Source Code <script type="text/javascript">      function mywiki(json)            {        var html=[ ];        varind = json.parse.text.*;        html.push(ind);       document.write(html);            }  </script>  <script type="text/javascript" src="http://en.wikipedia.org/w/api.php?action=parse&page=Bangalore&prop=text&format=json&callback=mywiki"></script> Raghavendra Nayak M
  • 43. Twitter Public Timeline Twitter is a micro blogging site. A list of Public Tweets is called as Public Timeline. Public Timeline doesn’t require Authentication to retrieve tweets. Raghavendra Nayak M
  • 44. URL Construction Base URL:-http://api.twitter.com/1/statuses/public_timeline.json Callback=<Callback Function> Raghavendra Nayak M
  • 45. Pub Tweet Function <script type="text/javascript">      function pubtweet(json)       {        for(i=0;i<6;i++)        {          varuname=json[i].user.name       varimg='<imgsrc="'+json[i].user.profile_image_url+'"/>';       vartwt=json[i].text;          document.write(img+uname+'</br>'+twt+'</br>');        }        }  </script> Raghavendra Nayak M
  • 46. Complete Source Code <script type="text/javascript">      function pubtweet(json)       {        for(i=0;i<6;i++)        {          varuname=json[i].user.name       varimg='<imgsrc="'+json[i].user.profile_image_url+'"/>';       vartwt=json[i].text;          document.write(img+uname+'</br>'+twt+'</br>');        }        }  </script>  <script type="text/javascript" src="http://api.twitter.com/1/statuses/public_timeline.json?count=3&include_entities=true&callback=pubtweet"></script> Raghavendra Nayak M
  • 47. Questions???? Mail me : rnayak@hotmail.com Thank You Raghavendra Nayak M