Introduction to JSON. Roger Lacroix MQ Technical Conference v

Similar documents
So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.

JSON is a light-weight alternative to XML for data-interchange JSON = JavaScript Object Notation

JSON as an XML Alternative. JSON is a light-weight alternative to XML for datainterchange

CSC Web Technologies, Spring Web Data Exchange Formats

NOSQL EGCO321 DATABASE SYSTEMS KANAT POOLSAWASD DEPARTMENT OF COMPUTER ENGINEERING MAHIDOL UNIVERSITY

COMP9321 Web Application Engineering

JSON - Overview JSon Terminology

IBM Informix xC2 Enhancements IBM Corporation

Assigns a number to 110,000 letters/glyphs U+0041 is an A U+0062 is an a. U+00A9 is a copyright symbol U+0F03 is an

Flat triples approach to RDF graphs in JSON

User Interaction: XML and JSON

CSE 344 APRIL 16 TH SEMI-STRUCTURED DATA

Kyle Rainville Littleton Coin Company

B4M36DS2, BE4M36DS2: Database Systems 2

Packaging Data for the Web

10/18/2017. Announcements. NoSQL Motivation. NoSQL. Serverless Architecture. What is the Problem? Database Systems CSE 414

XML. Jonathan Geisler. April 18, 2008

Grading for Assignment #1

CSC 337. JavaScript Object Notation (JSON) Rick Mercer

[301] JSON. Tyler Caraza-Harter

/ Introduction to XML

REST. Web-based APIs

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

External data representation

Web Scraping XML/JSON. Ben McCamish

Introduction to XML. Asst. Prof. Dr. Kanda Runapongsa Saikaew Dept. of Computer Engineering Khon Kaen University

Java EE 7: Back-end Server Application Development 4-2

This tutorial will help you understand JSON and its use within various programming languages such as PHP, PERL, Python, Ruby, Java, etc.

5/1/17. Announcements. NoSQL Motivation. NoSQL. Serverless Architecture. What is the Problem? Database Systems CSE 414

Introduction to XML 3/14/12. Introduction to XML

Introduction to Azure DocumentDB. Jeff Renz, BI Architect RevGen Partners

5/2/16. Announcements. NoSQL Motivation. The New Hipster: NoSQL. Serverless. What is the Problem? Database Systems CSE 414

Database Systems CSE 414

Announcements. Two Classes of Database Applications. Class Overview. NoSQL Motivation. RDBMS Review: Serverless

Assignment #3 CSCI 201 Spring % of course grade Title Weathermeister Back-End API Integration

Class Overview. Two Classes of Database Applications. NoSQL Motivation. RDBMS Review: Client-Server. RDBMS Review: Serverless

Data Formats and APIs


Announcements. JSon Data Structures. JSon Syntax. JSon Semantics: a Tree! JSon Primitive Datatypes. Introduction to Database Systems CSE 414

markup language carry data define your own tags self-descriptive W3C Recommendation

Elliotte Rusty Harold August From XML to Flat Buffers: Markup in the Twenty-teens

CSCE 156 Computer Science II

Intro to XML. Borrowed, with author s permission, from:

relational Key-value Graph Object Document

CSE 344 FEBRUARY 2 ND DATA SEMI-STRUCTURED

11. EXTENSIBLE MARKUP LANGUAGE (XML)

Data Presentation and Markup Languages

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Computer Science & Engineering 120 Learning to Code

JSON Support for Junos OS

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 27-1

JME Language Reference Manual

What is PHP? [1] Figure 1 [1]

Session 14. Serialization/JSON. Lecture Objectives

Utilizing Nested Normal Form to Design Redundancy Free JSON Schemas

Honu. Version November 6, 2010

6 7. APRIL ATLANTA, GA, USA. Building for the future. Better, faster, everywhere. Building for the future. Better, faster, everywhere.

Cloud-based Database Systems (No SQL Databases) Reference: Chapter 19.9, Database Systems Concepts, Silberschatz, et al.

Data Formats. Course NDBI040: Big Data Management and NoSQL Databases. Lecture 06: Martin Svoboda

XML JavaScript Object Notation JSON Cookies Miscellaneous What Javascript can t do. OOP Concepts of JS

CONTRACTOR IS ACTING UNDER A FRAMEWORK CONTRACT CONCLUDED WITH THE COMMISSION

Data Collections. Welcome to the Fourth Dimension (and beyond) Martin Phillips Ladybridge Systems Ltd. International Spectrum Conference, 2014

CSE 344 JULY 9 TH NOSQL

EMERGING TECHNOLOGIES. XML Documents and Schemas for XML documents

Processing XML and JSON in Python

XML Processing & Web Services. Husni Husni.trunojoyo.ac.id

Introduction Syntax and Usage XML Databases Java Tutorial XML. November 5, 2008 XML

W3C XML XML Overview

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

SEEM4570 System Design and Implementation Lecture 03 JavaScript

Serialization. Lab 1 JSON

- What is a markup language? - What is a data serialization language?

Introduction to XML Zdeněk Žabokrtský, Rudolf Rosa

Processing and Creating JSON from RPG

H2 Spring B. We can abstract out the interactions and policy points from DoDAF operational views

Boolean evaluation and if statements. Making decisions in programs

Lists, loops and decisions

7.1 Introduction. extensible Markup Language Developed from SGML A meta-markup language Deficiencies of HTML and SGML

Chapter 13 XML: Extensible Markup Language

Semistructured Data and XML

Delivery Options: Attend face-to-face in the classroom or remote-live attendance.

NeoJSON. 1.1 An Introduction to JSON

Copyright 2014 Blue Net Corporation. All rights reserved

Decision Making in C

Avancier Methods (AM) Data Architecture

JavaScript Lecture 1

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

Introduction to XML. Chapter 133

COMP9321 Web Application Engineering

[Rosa Say on flickr] Module 12 Tree-Structured data CS 106 Winter 2018

Chapter 2 The relational Model of data. Relational model introduction

JSON Analyse and Transform for Access (JATFA)

COMP9321 Web Application Engineering. Extensible Markup Language (XML)

Overview. * Some History. * What is NoSQL? * Why NoSQL? * RDBMS vs NoSQL. * NoSQL Taxonomy. *TowardsNewSQL

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

CSE 115. Introduction to Computer Science I

CSCE 120: Learning To Code

Documenting APIs with Swagger. TC Camp. Peter Gruenbaum

DC71 INTERNET APPLICATIONS JUNE 2013

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Transcription:

Introduction to JSON Roger Lacroix roger.lacroix@capitalware.com http://www.capitalware.com

What is JSON? JSON: JavaScript Object Notation. JSON is a simple, text-based way to store and transmit structured data. By using a simple syntax, the user can easily store anything from a single number through to strings, arrays, and objects using nothing but a string of plain text. You can also nest arrays and objects, allowing you to create complex data structures.

What is JSON? JSON is a syntax for storing and exchanging data. JSON is text (no binary data). JSON is a lightweight data-interchange format JSON is "self-describing" and easy to understand JSON is language independent.

Why use JSON? Since the JSON format is text only, it can easily be sent to and from a server, and used as a data format by any programming language. For IBM MQ, setting the message's Format attribute to 'MQSTR' (String) then when the receiving application performs an 'MQGET with Convert', MQ will convert the text from one CCSID to another CCSID. i.e. ASCII to EBCDIC

JSON is NOT Overly Complex A 'document' format A markup language A programming language

JSON Syntax

JSON Syntax Rules Data is in name/value pairs Data is separated by commas Curly braces hold objects i.e. { } Square brackets hold arrays i.e. [ ]

JSON Object Syntax Unordered sets of name/value pairs Starts with { (left brace) Ends with } (right brace) Each name is followed by : (colon) and then its value Name/value pairs are separated by, (comma)

JSON Data - A Name and a Value JSON data is written as name/value pairs. A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value: Example { "name" : "John" }

JSON Arrays An ordered collection of values Starts with [ (left bracket) Ends with ] (right bracket) Name/value pairs are separated by, (comma)

JSON Array Example { "name" : "John", "cars" : [ "Ford", "BMW", "Fiat" ] }

JSON Data Types

JSON Values In JSON, values must be one of the following data types: a string a number an object (JSON object) an array a boolean null JSON values cannot be one of the following data types: a function a date undefined

JSON Strings Strings in JSON must be written in double quotes. Example { "name" : "John" }

JSON Numbers Numbers in JSON must be an integer or a floating point. Example { "age" : 30 }

JSON Objects Values in JSON can be objects. Example { "employee" : { "name" : "John", "age" : 30, "city" : "New York" } }

JSON Arrays Values in JSON can be arrays. Example { "employees" : [ "John", "Anna", "Peter" ] }

JSON Booleans Values in JSON can be true or false. Example { "sale" : true }

JSON null Values in JSON can be null. Example { "middlename" : null }

Nested JSON Objects Values in a JSON object can be another JSON object. Example myobj = { "name":"john", "age":30, "cars" : { "car1" : "Ford", "car2" : "BMW", "car3" : "Fiat" } } x = myobj.cars["cars2"];

Arrays in JSON Objects Arrays can be values of an object property: Example myobj = { "name" : "John", "age" : 30, "cars" : [ "Ford", "BMW", "Fiat" ] } x = myobj.cars[0];

Nested Arrays in JSON Objects Values in an array can also be another array, or even another JSON object: Example myobj = { "name" : "John", "age" : 30, "cars" : [ { "name" : "Ford", "models":[ "Fiesta", "Focus", "Mustang" ] }, { "name" : "BMW", "models" : [ "320", "X3", "X5" ] }, { "name" : "Fiat", "models" : [ "500", "Panda" ] } ] } To access arrays inside arrays, use a for-in loop for each array: for (i in myobj.cars) { x += "<h1>" + myobj.cars[i].name + "</h1>"; for (j in myobj.cars[i].models) { x += myobj.cars[i].models[j]; } }

JSON Data Example

JSON vs XML Both JSON and XML can be used as a data format when sending/receiving data between servers. The following JSON and XML examples both defines an employees object, with an array of 3 employees:

JSON vs XML {"employees": [ { "firstname":"john", "lastname":"doe" }, { "firstname":"anna", "lastname":"smith" }, { "firstname":"peter", "lastname":"jones" } ] } <employees> <employee> <firstname>john</firstname> <lastname>doe</lastname> </employee> <employee> <firstname>anna</firstname> <lastname>smith</lastname> </employee> <employee> <firstname>peter</firstname> <lastname>jones</lastname> </employee> </employees>

JSON vs XML JSON is like XML because: Both JSON and XML are "self describing" (human readable) Both JSON and XML are hierarchical (values within values) Both JSON and XML can be parsed and used by lots of programming languages

JSON vs XML JSON is unlike XML because: JSON doesn't use end tag JSON is shorter JSON is quicker to read and write JSON can use arrays

JSON vs XML Since XML is widely used as data interchange format, we will try to draw a comparison between them. The purpose of the comparison is not to determine which is better but rather we will try to understand which one is suitable for storing specific kind of data.

JSON vs XML XML is more expressive than JSON. XML sometimes also suffers from using tags repeatedly, where as JSON is much more concise. XML is more complex than JSON. JSON lacks namespaces There are several specifications to define schema(metadata) for XML, for example DTD and XSD. JSON schema is available but is not as widely used as XML schemas.

JSON vs XML XML and JSON can be used with most of the programming languages. The problem comes when matching XML tags used by one system may be different in another system, hence, XML data will require transformation. i.e. <FirstName> vs <first_name>. In the case of JSON, since objects and arrays are basic data structures used, it is easy to work with them in programs. For selecting specific parts of an XML document, there is standard specification called XPath. This is widely used. In JSON, we have JSONPath to do the same, but it is not widely used. XML has Xquery specification for querying XML data. JSON does have JAQL, JSONiq etc, but they are not in use widely. XML has XSLT specification which may be used to apply a style to an XML document. JSON does not have any such thing.

JSON vs XML Favor XML over JSON when any of these is true: You need message validation You're using XSLT Your messages include a lot of marked-up text You need to inter-operate with environments that don't support JSON Favor JSON over XML when all of these are true: Messages don't need to be validated You're not transforming messages Your messages are mostly data, not marked-up text The messaging endpoints have good JSON tools

Java and JSON JEE (Java Enterprise Edition) includes a JSON parser. https://docs.oracle.com/javaee/7/tutorial/jsonp001.htm JSE (Java Standard Edition) does not include a JSON parser. I suggest you use the Google-Gson parser for JSE projects. https://github.com/google/gson https://en.wikipedia.org/wiki/gson https://github.com/google/gson/blob/master/userguide.md

Questions & Answers