SlideShare a Scribd company logo
Introduction to  Introduction to JSON (JavaScript  (JavaScript Object Notation)
Topics What is JSON? JSON Data Structure >   JSON Object >   JSON text How to send and receive JSON data at both client and server sides Resources
What is JSON?   Lightweight data-interchange format >  Compared to XML Simple format >   Easy for humans to read and write >  Easy for machines to parse and generate JSON is a text format >  Programming language independent >  Uses conventions that are familiar to programmers of the C family of languages, including C, C++, C#, Java, JavaScript, Perl, Python
JSON Object
JSON Structures   A collection of name/value pairs >   In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array An ordered list of values >   In most languages, this is realized as an array, vector, list, or sequence These are universal data structures supported by most modern programming languages
JSON Object Notation   A JSON object is an unordered set of name/value pairs A JSON object begins with { (left brace) and ends with } (right brace) Each name is followed by : (colon) and the name/value pairs are separated by , (comma)
JSON and JavaScript JSON is a subset of the object literal notation of JavaScript >   JSON can be used in the JavaScript language with no muss or fuss
Example: JSON Object   var myJSONObject = {"bindings": [ {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"}, {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"}, {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"} ] };
Example: JSON Object Cont.. In this example, a JSON JavaScript object is created containing a single member "bindings", which contains an array containing three objects, each containing "ircEvent", "method", and "regex" members Members can be retrieved using dot or subscript operators  myJSONObject.bindings[0].method // "newURI"
Text to Object Conversion in JavaScript code   var myObject = eval('(' + myJSONtext + ')'); To convert a JSON text into an JSON object, use the  eval()  function >   eval() invokes the JavaScript compiler >   Since JSON is a proper subset of JavaScript, the compiler will correctly parse the text and produce an object structure
Security & JSON Parser   // Include http://www.json.org/json.js var myObject = myJSONtext.parseJSON(); eval()  can compile and execute any JavaScript program, so there can be security issues (cross-site scripting) >   Use eval() when the source can be trusted When security is a concern - the source cannot be trusted -, it is better to use a JSON parser >   A JSON parser will only recognize JSON text and so is much safer
Object to Text Conversion   var myJSONText = myObject.toJSONString(); You can convert JSON object into JSON text JSON does not support cyclic data structure >   Do not give cyclical structures to the JSON stringifier
How to Send & Receive JSON Data at Both Client and Server Side
How to Generate/Send JSON Data at the Server Side   Create  JSONObject  Java object Add name/value pairs using  put  method Convert it to  String  type using  toString  method and send it to the client with content-type as “text/xml” or “text/plain” myString = new JSONObject().put("JSON", "Hello, World!").toString(); // myString is {"JSON": "Hello, World"}
How to Receive JSON Data at the Client Side   JSON data is received as a string Calling  eval()  will generate JSON object in JavaScript code >   var JSONdata = eval(req.responseText); Once you have JSON object, you can use . Notation to access its properties >   var name = JSONdata.name; >   var address = JSONdata.addresses[3]; >   var streetname = JSONdata.addresses[3].street;
How to Generate/Send JSON Data at the Client Side   Use “POST” HTTP method in the  open  method of the XMLHttpRequest object Create JSON JavaScript object Pass JSON JavaScript object in the  send  method of XMLHttpRequest object
How to Generate/Send JSON Data at the Client Side Cont… var carAsJSON = JSON.stringify(car); var url = "JSONExample?timeStamp=" + new Date().getTime(); createXMLHttpRequest(); xmlHttp.open("POST", url, true); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlHttp.send(carAsJSON);
How to Receive JSON Data at the Server Side   Read the JSON data as a String type Create  JSONObject  Java object from the string String json = readJSONStringFromRequestBody(request); //Use the JSON-Java binding library to create a JSON object in Java JSONObject jsonObject = null; try { jsonObject = new JSONObject(json); } catch(ParseException pe) { }
JSON Resources Introducing JSON >   http://www.json.org/ JSON in JavaScript >   http://www.json.org/js.html
 
 

More Related Content

PPT
Javascript2839
Ramamohan Chokkam
 
PDF
Jsonsaga 100605143125-phpapp02
Ramamohan Chokkam
 
PDF
Json the-x-in-ajax1588
Ramamohan Chokkam
 
PDF
Automatically generating-json-from-java-objects-java-objects268
Ramamohan Chokkam
 
PPT
Json
mussawir20
 
PDF
Apache AVRO (Boston HUG, Jan 19, 2010)
Cloudera, Inc.
 
PPTX
JSON(JavaScript Object Notation)
Raghu nath
 
Javascript2839
Ramamohan Chokkam
 
Jsonsaga 100605143125-phpapp02
Ramamohan Chokkam
 
Json the-x-in-ajax1588
Ramamohan Chokkam
 
Automatically generating-json-from-java-objects-java-objects268
Ramamohan Chokkam
 
Apache AVRO (Boston HUG, Jan 19, 2010)
Cloudera, Inc.
 
JSON(JavaScript Object Notation)
Raghu nath
 

What's hot (20)

PDF
Basics of JSON (JavaScript Object Notation) with examples
Sanjeev Kumar Jaiswal
 
PPTX
JSON-(JavaScript Object Notation)
Skillwise Group
 
PPT
Introduction To Groovy 2005
Tugdual Grall
 
PPT
JavaScript Object Notation (JSON)
BOSS Webtech
 
PPTX
JSON: The Basics
Jeff Fox
 
PDF
Elasticsearch And Ruby [RuPy2012]
Karel Minarik
 
PDF
Search Engine-Building with Lucene and Solr
Kai Chan
 
PDF
Elasticsearch (Rubyshift 2013)
Karel Minarik
 
PPT
Json - ideal for data interchange
Christoph Santschi
 
PDF
Elasticsearch in 15 Minutes
Karel Minarik
 
ODP
Terms of endearment - the ElasticSearch Query DSL explained
clintongormley
 
PDF
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Zalando Technology
 
PDF
Json tutorial, a beguiner guide
Rafael Montesinos Muñoz
 
PDF
GraphQL & Relay - 串起前後端世界的橋樑
Pokai Chang
 
PPTX
Java Development with MongoDB
Scott Hernandez
 
PPT
Reversing JavaScript
Roberto Suggi Liverani
 
PDF
The emerging world of mongo db csp
Carlos Sánchez Pérez
 
PPTX
Java and XML
Raji Ghawi
 
PDF
MongoDB and Ruby on Rails
rfischer20
 
Basics of JSON (JavaScript Object Notation) with examples
Sanjeev Kumar Jaiswal
 
JSON-(JavaScript Object Notation)
Skillwise Group
 
Introduction To Groovy 2005
Tugdual Grall
 
JavaScript Object Notation (JSON)
BOSS Webtech
 
JSON: The Basics
Jeff Fox
 
Elasticsearch And Ruby [RuPy2012]
Karel Minarik
 
Search Engine-Building with Lucene and Solr
Kai Chan
 
Elasticsearch (Rubyshift 2013)
Karel Minarik
 
Json - ideal for data interchange
Christoph Santschi
 
Elasticsearch in 15 Minutes
Karel Minarik
 
Terms of endearment - the ElasticSearch Query DSL explained
clintongormley
 
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Zalando Technology
 
Json tutorial, a beguiner guide
Rafael Montesinos Muñoz
 
GraphQL & Relay - 串起前後端世界的橋樑
Pokai Chang
 
Java Development with MongoDB
Scott Hernandez
 
Reversing JavaScript
Roberto Suggi Liverani
 
The emerging world of mongo db csp
Carlos Sánchez Pérez
 
Java and XML
Raji Ghawi
 
MongoDB and Ruby on Rails
rfischer20
 
Ad

Similar to J s-o-n-120219575328402-3 (20)

PPTX
JSON & AJAX.pptx
dyumna2
 
PPT
Zend framework 05 - ajax, json and j query
Tricode (part of Dept)
 
PPT
Json
elliando dias
 
PPT
Javascript Templating
bcruhl
 
PPTX
Json
Steve Fort
 
PPT
Itemscript, a specification for RESTful JSON integration
{item:foo}
 
PPT
Javascript
mussawir20
 
PPT
Advanced Json
guestfd7d7c
 
ODP
Testing RESTful Webservices using the REST-assured framework
Micha Kops
 
PPT
OSS BarCamp Mumbai - JSON Presentation and Demo
Ketan Khairnar
 
PPT
Implementing Ajax In ColdFusion 7
Pranav Prakash
 
ODP
REST dojo Comet
Carol McDonald
 
PPTX
Introduction to JSON & AJAX
Raveendra R
 
PPTX
Web Development Course - AJAX & JSON by RSOLUTIONS
RSolutions
 
PPT
Java Script Object Notation (JSON)
Adnan Sohail
 
PPT
Introduction to Prototype JS Framework
Mohd Imran
 
JSON & AJAX.pptx
dyumna2
 
Zend framework 05 - ajax, json and j query
Tricode (part of Dept)
 
Javascript Templating
bcruhl
 
Itemscript, a specification for RESTful JSON integration
{item:foo}
 
Javascript
mussawir20
 
Advanced Json
guestfd7d7c
 
Testing RESTful Webservices using the REST-assured framework
Micha Kops
 
OSS BarCamp Mumbai - JSON Presentation and Demo
Ketan Khairnar
 
Implementing Ajax In ColdFusion 7
Pranav Prakash
 
REST dojo Comet
Carol McDonald
 
Introduction to JSON & AJAX
Raveendra R
 
Web Development Course - AJAX & JSON by RSOLUTIONS
RSolutions
 
Java Script Object Notation (JSON)
Adnan Sohail
 
Introduction to Prototype JS Framework
Mohd Imran
 
Ad

Recently uploaded (20)

PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
The Future of Artificial Intelligence (AI)
Mukul
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 

J s-o-n-120219575328402-3

  • 1. Introduction to Introduction to JSON (JavaScript (JavaScript Object Notation)
  • 2. Topics What is JSON? JSON Data Structure > JSON Object > JSON text How to send and receive JSON data at both client and server sides Resources
  • 3. What is JSON? Lightweight data-interchange format > Compared to XML Simple format > Easy for humans to read and write > Easy for machines to parse and generate JSON is a text format > Programming language independent > Uses conventions that are familiar to programmers of the C family of languages, including C, C++, C#, Java, JavaScript, Perl, Python
  • 5. JSON Structures A collection of name/value pairs > In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array An ordered list of values > In most languages, this is realized as an array, vector, list, or sequence These are universal data structures supported by most modern programming languages
  • 6. JSON Object Notation A JSON object is an unordered set of name/value pairs A JSON object begins with { (left brace) and ends with } (right brace) Each name is followed by : (colon) and the name/value pairs are separated by , (comma)
  • 7. JSON and JavaScript JSON is a subset of the object literal notation of JavaScript > JSON can be used in the JavaScript language with no muss or fuss
  • 8. Example: JSON Object var myJSONObject = {"bindings": [ {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"}, {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"}, {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"} ] };
  • 9. Example: JSON Object Cont.. In this example, a JSON JavaScript object is created containing a single member "bindings", which contains an array containing three objects, each containing "ircEvent", "method", and "regex" members Members can be retrieved using dot or subscript operators myJSONObject.bindings[0].method // "newURI"
  • 10. Text to Object Conversion in JavaScript code var myObject = eval('(' + myJSONtext + ')'); To convert a JSON text into an JSON object, use the eval() function > eval() invokes the JavaScript compiler > Since JSON is a proper subset of JavaScript, the compiler will correctly parse the text and produce an object structure
  • 11. Security & JSON Parser // Include http://www.json.org/json.js var myObject = myJSONtext.parseJSON(); eval() can compile and execute any JavaScript program, so there can be security issues (cross-site scripting) > Use eval() when the source can be trusted When security is a concern - the source cannot be trusted -, it is better to use a JSON parser > A JSON parser will only recognize JSON text and so is much safer
  • 12. Object to Text Conversion var myJSONText = myObject.toJSONString(); You can convert JSON object into JSON text JSON does not support cyclic data structure > Do not give cyclical structures to the JSON stringifier
  • 13. How to Send & Receive JSON Data at Both Client and Server Side
  • 14. How to Generate/Send JSON Data at the Server Side Create JSONObject Java object Add name/value pairs using put method Convert it to String type using toString method and send it to the client with content-type as “text/xml” or “text/plain” myString = new JSONObject().put("JSON", "Hello, World!").toString(); // myString is {"JSON": "Hello, World"}
  • 15. How to Receive JSON Data at the Client Side JSON data is received as a string Calling eval() will generate JSON object in JavaScript code > var JSONdata = eval(req.responseText); Once you have JSON object, you can use . Notation to access its properties > var name = JSONdata.name; > var address = JSONdata.addresses[3]; > var streetname = JSONdata.addresses[3].street;
  • 16. How to Generate/Send JSON Data at the Client Side Use “POST” HTTP method in the open method of the XMLHttpRequest object Create JSON JavaScript object Pass JSON JavaScript object in the send method of XMLHttpRequest object
  • 17. How to Generate/Send JSON Data at the Client Side Cont… var carAsJSON = JSON.stringify(car); var url = "JSONExample?timeStamp=" + new Date().getTime(); createXMLHttpRequest(); xmlHttp.open("POST", url, true); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlHttp.send(carAsJSON);
  • 18. How to Receive JSON Data at the Server Side Read the JSON data as a String type Create JSONObject Java object from the string String json = readJSONStringFromRequestBody(request); //Use the JSON-Java binding library to create a JSON object in Java JSONObject jsonObject = null; try { jsonObject = new JSONObject(json); } catch(ParseException pe) { }
  • 19. JSON Resources Introducing JSON > http://www.json.org/ JSON in JavaScript > http://www.json.org/js.html
  • 20.  
  • 21.