OVERVIEW AND PARSING JSON. What is JSON JavaScript Object Notation Used to format data Commonly used in Web as a vehicle to describe data being sent between.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Copyright © Steven W. Johnson
Special Topic JSON. Introducing JSON JSON (JavaScript ObjectNotation): A data format based on the object literal format Advantage of JSON over XML – JSON.
An Introductory Tutorial. Background and Purpose.
JSON Valery Ivanov.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
JavaScript, Third Edition
15-Jul-15 JSON. JSON example “JSON” stands for “JavaScript Object Notation” Despite the name, JSON is a (mostly) language-independent way of specifying.
JSON (JavaScript Object Notation).  A lightweight data-interchange format  A subset of the object literal notation of JavaScript (or ECMA-262).  A.
JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
Web Server Administration Web Services XML SOAP. Overview What are web services and what do they do? What is XML? What is SOAP? How are they all connected?
Chapter 3: Data Types and Operators JavaScript - Introductory.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Copyright © Curt Hill Sounds, Resource Packs, JSON What more would you want?
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Softsmith Infotech XML. Softsmith Infotech XML EXtensible Markup Language XML is a markup language much like HTML Designed to carry data, not to display.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Serialization. Serialization is the process of converting an object into an intermediate format that can be stored (e.g. in a file or transmitted across.
JSON Java Script Object Notation Copyright © 2013 Curt Hill.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
JSON and A Comparison of Scripts. JSON: JavaScript Object Notation Based on a subset of the JavaScript Programming Language provides a standardized data.
JavaScript Syntax, how to use it in a HTML document
JSON – Java Script Object Notation. What is JSON JSON is a data interchange format Interactive Web 2.0 applications, no more use page replacement. Data.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
JSON. JSON as an XML Alternative JSON is a light-weight alternative to XML for data- interchange JSON = JavaScript Object Notation It’s really language.
JSON (Copied from and from Prof Da Silva) Week 12 Web site:
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
Web Services Essentials. What is a web service? web service: software functionality that can be invoked through the internet using common protocols like.
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Unit 4 Representing Web Data: XML
“Under the hood”: Angry Birds Maze
CSE 3302 Programming Languages
AJAX and REST.
Exporting and Importing Data
JSON Crash Course Traversy Media.
Exporting and Importing Data
Scope, Objects, Strings, Numbers
Consuming Java Script Object Notation (JSON) feeds
JavaScript Object Notation
JSON Object and JSON Schema
Chapter 7 Representing Web Data: XML
JavaScript an introduction.
Web Server Administration
Built in Fairfield County: Front End Developers Meetup
Tree Visualization.
Chapter 8 JavaScript: Control Statements, Part 2
WEB PROGRAMMING JavaScript.
JSON.
PHP.
2017, Fall Pusan National University Ki-Joune Li
JSON for the Data Mortal
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Department of Computer Science Cal State East Bay, Hayward, CA
CS 240 – Advanced Programming Concepts
Tutorial 10: Programming with javascript
JSON: JavaScript Object Notation
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

OVERVIEW AND PARSING JSON

What is JSON JavaScript Object Notation Used to format data Commonly used in Web as a vehicle to describe data being sent between systems

JSON example “JSON” stands for “JavaScript Object Notation” Despite the name, JSON is a (mostly) language-independent way of specifying objects as name-value pairs Example ( ): {"skillz": { "web":[ { "name": "html", "years": 5 }, { "name": "css", "years": 3 }] "database":[ { "name": "sql", "years": 7 }] }}

JSON syntax An object is an unordered set of name/value pairs The pairs are enclosed within braces, { } There is a colon between the name and the value Pairs are separated by commas Example: { "name": "html", "years": 5 } An array is an ordered collection of values The values are enclosed within brackets, [ ] Values are separated by commas Example: [ "html", ”xml", "css" ]

JSON syntax A value can be: A string, a number, true, false, null, an object, or an array Values can be nested Strings are enclosed in double quotes, and can contain the usual assortment of escaped characters Numbers have the usual C/C++/Java syntax, including exponential (E) notation All numbers are decimal--no octal or hexadecimal Whitespace can be used between any pair of tokens

How to turn JSON into JavaScript object –eval(*) The JavaScript eval( string ) method compiles and executes the given string The string can be an expression, a statement, or a sequence of statements Expressions can include variables and object properties eval returns the value of the last expression evaluated When applied to JSON, eval returns the described object

JSON and—methods? In addition to instance variables, objects typically have methods There is nothing in the JSON specification about methods However, a method can be represented as a string, and (when received by the client) evaluated with eval Obviously, this breaks language-independence Also, JavaScript is rarely used on the server side

Comparison of JSON and XML Similarities: Both are human readable Both have very simple syntax Both are hierarchical Both are language independent Both can be used by Ajax Both supported in APIs of many programming languages Differences: Syntax is different JSON is less verbose JSON can be parsed by JavaScript’s eval method JSON includes arrays Names in JSON must not be JavaScript reserved words XML can be validated

JSON in AJAX JSON can be used in AJAX as follows: Include it in HTML directly... var data = JSONdata;... JSON is used with XMLHttpRequest and can be converted into a JavaScript structure responseData = eval('(' + responseText + ')'); We have not yet spoken about AJAX --- revisit this again after you have learned about AJAX

Why is JSON better suited for AJAX? JSON is widely used in AJAX. The X in AJAX stands for XML. E.g. { "fullname": "Swati Kumar", "org": "Columbia", } Swati Kumar Columbia

JSON response at client side is: var name = eval('(' + req.responseText + ')').fullname.value; To access a composite element eval('(' + req.responseText + ')').xyz.abc.value; Thus, any level deep elements can be easily accessed.

XML and JavaScript XML response at client side is: var root = req.responseXML; var name = root.getElementsByTagName(‘fullname’); To access a composite element root.getElementsByTagName(‘xyz’)[0].firstChild To access deeper levels we need more overhead. Reduced extensibility in XML

YAML – another option? YAML can be taken as an acronym for either Yet Another Markup Language YAML Ain’t Markup Language Like JSON, the purpose of YAML is to represent typical data types in human-readable notation YAML is (almost) a superset of JSON, with many more capabilities (lists, casting, etc.) Except: YAML doesn’t handle escaped Unicode characters Consequently, JSON can be parsed by YAML parsers When JSON isn’t enough, consider YAML

HOW TO PARSE JSON IN JAVA JSON and Java

Mapping between JSON and Java entities JSONJava stringjava.lang.String numberjava.lang.Number true|falsejava.lang.Boolean null arrayjava.util.List objectjava.util.Map JSON.simple maps entities from the left side to the right side while decoding or parsing, and maps entities from the right to the left while encoding. On decoding, the default concrete class of java.util.List isorg.json.simple.JSONArray and the default concrete class of java.util.Map isorg.json.simple.JSONObject.

JSON reading in Java example m

There is an interface called JSONParser in javax.json.stream you can implement javax.json.stream Interface JsonParserJsonParser