JSON++ - A Simple class library for JSON

Slides:



Advertisements
Similar presentations
SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Advertisements

What's new in Microsoft Visual C Preview
Constants and Data Types Constants Data Types Reading for this class: L&L,
Guide To UNIX Using Linux Third Edition
-Uday Dhokale.  What is it ??? Prototype is a JavaScript Framework that aims to ease development of dynamic web applications.  Features a unique, easy-to-use.
15-Jul-15 JSON. JSON example “JSON” stands for “JavaScript Object Notation” Despite the name, JSON is a (mostly) language-independent way of specifying.
4/20/2017.
JSON (JavaScript Object Notation).  A lightweight data-interchange format  A subset of the object literal notation of JavaScript (or ECMA-262).  A.
JSP Standard Tag Library
JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.
Session 1 - Introduction and Data Access Layer
CIS Computer Programming Logic
WEB API: WHY THEY MATTER ECOL 453/ Nirav Merchant
Open Data Protocol * Han Wang 11/30/2012 *
Chapter 8 Cookies And Security JavaScript, Third Edition.
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
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.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
JSON Java Script Object Notation Copyright © 2013 Curt Hill.
JSON and A Comparison of Scripts. JSON: JavaScript Object Notation Based on a subset of the JavaScript Programming Language provides a standardized data.
JSTL The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.
Martin Kruliš by Martin Kruliš (v1.1)1.
“The world’s most misunderstood language has become the world’s most popular programming language” Akshay Arora
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
 Packages:  Scrapy, Beautiful Soup  Scrapy  Website  
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
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.
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:
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Presented By Sushil K. Chaturvedi Assistant Professor SRCEM,Banmore 1.
Introduction to Mongo DB(NO SQL data Base)
Web Database Programming Using PHP
XML: Extensible Markup Language
Unit 4 Representing Web Data: XML
CS240: Advanced Programming Concepts
Using JMP® Visualization for A Bike-Sharing Program in NYC
Chapter 6: Data Types Lectures # 10.
Web Database Programming Using PHP
Data Types and Structures
AJAX and REST.
JSON Crash Course Traversy Media.
Scope, Objects, Strings, Numbers
XML in Web Technologies
Knowledge Byte In this section, you will learn about:
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Introduction to Internet Programming
Chapter 7 Representing Web Data: XML
JavaScript an introduction.
Introduction to Python
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
Built in Fairfield County: Front End Developers Meetup
Instance Model Structure
An overview of Java, Data types and variables
PHP.
Introduction to Primitive Data types
Web DB Programming: PHP
CS5220 Advanced Topics in Web Programming JavaScript Basics
CS3220 Web and Internet Programming JavaScript Basics
Department of Computer Science Cal State East Bay, Hayward, CA
CS 240 – Advanced Programming Concepts
CS3220 Web and Internet Programming JavaScript Basics
Web Application Development Using PHP
Introduction to Primitive Data types
Presentation transcript:

JSON++ - A Simple class library for JSON PJ Naughter UL Identity Management & Security Microsoft MVP in Visual Studio and Development Technologies Dublin C/C++ Users Group Presentation (11 June 2018)

Talk Agenda JSON Introduction JSON Data Types Sample JSON JSON Pointer JSON++ Features JSON++ Implementation JSON++ Performance Further Reading

JSON Introduction JSON is a designed as a lightweight data-interchange format Based on a subset of the JavaScript Programming Language which is an ECMA standard Is a text format but uses conventions familiar to the C-family of program languages including C, C++, C#, Java, JavaScript, Perl & Python JSON is quite a compact specification (http://json.org) and boils down to roughly just three pages and 350 words. Uses a simple flow diagramming metaphor to describe the various parts of the specification. This is IMHO the main reason for its popularity in modern micro service based development when compared to XML. Is solely based on UTF-8 Unicode encoding. Unlike XML which supports all the complexity and flavours of Unicode such as UTF-16 (BE & LE), UTF-32 (BE & LE) and ASCII code pages and BOMs (Byte Order Markers). This is one of the reasons why developing an XML support library is so difficult as you need a comprehensive Unicode library to support XML itself. Examples of this would include Windows APIs or ICU (International Components for Unicode http://site.icu-project.org/)

JSON Data Types A JSON object is a collection of zero or more name value pairs. In a programming language this would corresponds to a struct, record, dictionary, hash table or associative array. Represented as “{ ...... }” A JSON array is an ordered list of zero or more values. In a programming language this corresponds to an array, vector, list or sequence. Represented as “[ …… ]” A pair is two values represented as “string : value” A value itself can be a string, number, object, array, “true”, “false” or “null”. A string can be sequence of zero or more Unicode characters. The spec has details on how a string can be encoded into a valid JSON representation A number is some numeric value. A JSON support library / framework is free to implement / represent this however it sees fit. In C++ if you were to encode all numbers to one type you would probably use the IEEE 754 “double” data type. Again the spec specifies how a number can be encoded into a valid JSON representation “true” represents a positive boolean value “false” represents a negative boolean value “null” represents a null value in the same sense as a database null value i.e. not a value.

Sample JSON { "string_name" : "string value and a "quote" and a unicode char u00BE and a c:path or a /unix/path/", "bool_name" : true, "bool_second" : FaLsE, "null_name" : nULl, "negative" : -34.276, "sub_object" : { "foo" : "abc", "bar" : 1.35e2, "blah" : { "a" : "A", "b" : "B", "c" : "C" } }, "array_letters" : [ "a", "b", "c", [ 1, 2, 3 ] ] }";

JSON Pointer A JSON Object is a collection of zero or more name value pairs. In a programming language this would corresponds to a struct, record, dictionary, hash table or associative array. Represented as “{ ...... }” A JSON Array is an ordered list of zero or more values. In a programming language this corresponds Similar to XPath in XML, this allows specific JSON data to be selected / extracted using a string specifier or path Published as RFC (Internet Request for Comments) 6901 Separator used is “/” Because “~” and “/” have special meaning in JSON Pointer if you want to use these as literal values, then they need to be encoded using specific rules Strings in JSON Pointer follow the same encoding rules as for JSON itself Does not support more complicated concepts in XPath such as functions, selectors etc. A specific element in a JSON array can be accessed using a simple numeric offset A specific name / value pair in an object can be accessed by using the name of the pair There are other query languages / libraries for JSON such as JSONiq, JQ, OboeJS, jsonfilter, Postgres, SQLite & SQL Server

Sample JSON for JSON Pointer { "foo": ["bar", "baz"], "": 0, "a/b": 1, "c%d": 2, "e^f": 3, "g|h": 4, "i\\j": 5, "k\"l": 6, " ": 7, "m~n": 8 }

Sample JSON Pointer Queries "" returns the whole document "/foo" returns ["bar", "baz"] "/foo/0" returns "bar" "/" returns 0 "/a~1b" returns 1 "/c%d" returns 2 "/e^f" returns 3 "/g|h" returns 4 "/i\\j" returns 5 "/k\"l" returns 6 "/ " returns 7 "/m~0n" returns 8

JSON++ Features A simple C++ Header only Library for JSON Available at http://www.naughter.com/jsonpp.html Based on SimpleJSON C++ library A JSON value is represented via the CValue class in the JSONPP namespace The CValue class is modeled on std::variant and provides one class which can store any of the JSON data types and any sub elements Uses C++ placement new to optimize the storage of the data Takes advantage of C++ 11 features such as r-value references, move constructors and operator= methods

JSON++ Implementation Parsing of JSON is provided via CValue::Parse(const char* pszJSON) and CValue::Parse(const wchar_t* pszJSON). Returns a DOM representation in the current CValue instance Encoding of JSON is provided via std::wstring CValue::Encode(unsigned long nFlags = ENCODE_FLAGS::NONE) const. The nFlags value includes support for “Pretty Printing” JSON Pointer supported via CValue* CValue::JSONPointer(const char* pszJSONPointer) and CValue* CValue::JSONPointer(const wchar_t* pszJSONPointer) Implemented using just standard C++. No Windows dependencies. Uses std::codecvt_utf8_utf16 for UTF16 support. Currently only supported / compiled on Windows but should be easily ported to GCC/Linux with minimal effort Implemented in just 1500 lines of code Comprehensive set of unit tests included in the download

JSON++ Performance SimpleJSON originally had a member variable for all possible JSON data types. The current implementation has moved to a C style union with pointers to C++ class instances With the simple introduction of r-value references and move semantics JSON++ was 15% faster JSON++ was then reimplemented using a std::aligned_union to store only the current active JSON data type. Parsing is now 50% faster than SimpleJSON for x86 and 40% faster for x64 Encoding is roughly the same speed as SimpleJSON

Further Reading My Web site http://www.naughter.com JSON++ http://www.naughter.com/jsonpp.html My Blob https://naughter.wordpress.com My Email pjna@naughter.com JSON Specification http://json.org JSON Pointer https://tools.ietf.org/html/rfc6901 SimpleJSON C++ library https://github.com/MJPA/SimpleJSON simplejson Library for Python https://github.com/simplejson/simplejson JSON for Modern C++ https://github.com/nlohmann/json JQ http://stedolan.github.io/jq/ OboeJS http://oboejs.com/examples jsonfilter https://github.com/maxogden/jsonfilter