DB2 JSON capabilities, Part 1: Introduction to DB2 JSON

Rapidly changing application environments require a flexible mechanism to store and communicate data between different application tiers. JSON (Java™ Script Object Notation) has proven to be a key technology for mobile, interactive applications by reducing overhead for schema designs and eliminating the need for data transformations.

DB2® JSON enables developers to write applications using a popular JSON-oriented query language created by MongoDB to interact with data stored in IBM® DB2 for Linux®, UNIX®, and Windows® or in IBM® DB2 for z/OS®. This driver-based solution embraces the flexibility of the JSON data representation within the context of an RDBMS, which provides established enterprise features and quality of service. This DB2 JSON capability supports a command-line processor, a Java API, and a wire listener to work with JSON documents.

This article introduces the DB2 JSON technology, which is further described in detail with tutorials in subsequent articles of this series.

Bobbie J. Cochrane, Senior Technical Strategist, STSM, IBM

Bobbie Cochrane photoDr. Cochrane leads strategic initiatives for IBM's Information Management portfolio, such as NoSQL, Cloud, and Web 2.0. Throughout her career, she has championed the inclusion of new innovations from IBM research and industry into product, including PureXML, materialized views, triggers and constraints. She has authored several journal articles and papers in leading database conferences, and played a major role in the definition of the SQL3 standard for triggers, constraints, and cubes.



Kathy A. McKnight, DB2 Runtime Architect, STSM, IBM

Kathy McKnight photoKathy McKnight is a Senior Technical Staff Member at IBM, and runtime architect for DB2 for Linux, Unix, and Windows. Kathy has worked on DB2 since its first release, and has led the design and delivery of the engine support for many enhancements into the product, including PureXML and most recently JSON. Kathy was also instrumental in the design and delivery of DB2' Oracle compatibility features.



20 June 2013

Also available in Chinese Japanese

Introduction

A new era of application development

There is a new style of applications evolving, driven by many forces converging simultaneously. The rapid rise and ubiquity of mobile and social applications are stimulating increased levels of interaction between humans through electronic means. Cloud computing makes compute resources readily available, and the advent of big data technology makes it possible to derive insights over massive amounts of data collected from the internet, sensors and mobile devices. The availability of user interaction data, the ease of access to compute resources and the advances in big data technology enable businesses to predict a customer's behaviors and needs far better than they ever have before. All these forces together are providing new opportunities for businesses to engage with their customers in meaningful ways. In fact, consumers who use social media and mobile applications have come to expect applications that are engaging and easily accessible through many form factors, especially their mobile devices.

A new era of application development is emerging to respond to these new opportunities. No longer can applications take six to nine months or longer from concept to deployment. Applications emerge quickly to respond to a business problem or opportunity, and they are often short-lived. There are many different technologies being assembled to rapidly deliver solutions. However, JavaScript and JSON - JavaScript's data representation language, are common across most. Although this new way of developing applications is emerging from the startup communities, it is also increasingly used to address agile development needs in enterprises and the public sector.

These new applications are designed and delivered to mobile devices first, driving an increase in social and mobile interactions. Enterprises are now looking to quickly provide gateways to their enterprise systems in order for them to participate in these new mobile and social interactions. They are moving from a simple transaction based world to an interaction based world. Businesses need to be able to expand and complement enterprise systems of record with systems of engagement, and do this while maintaining the enterprise capabilities intact - robustness, privacy, security and high availability. IBM is embracing this use of JSON by implementing a popular JSON API, MongoDB API, in our DB2 platform.

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data exchange format which is specified in IETF RFC 4627. It is designed to be minimal, portable, textual and a subset of JavaScript, which is easy to implement, easy to read and easy to use. It is also language independent, since most languages have features that map easily to JSON. It is used to exchange data between programs written in all modern programming languages. Also, given that it is text format, it is readable by humans and machines.

The following is a simple example of a JSON document:

Listing 1. Simple example of a JSON document
{"isbn": "123-456-222",  
 "author": 
   [
    {
      "lastname": "Doe",
      "firstname": "Jane"
    },
    {
      "lastname": "Doe",
      "firstname": "John"
    }
   ],
 "title": "The Ultimate Database Study Guide",  
 "abstract": "What you always wanted to know about databases and were afraid to ask", 
 "price": 28.00, 
 "sales": 
    {"qty": 1234,
      "amt": 31532.50
    },
 "category": ["Non-Fiction", "Technology"],
 "ratings": [10, 5, 32, 78, 112]
}

JSON facilitates the portability of structured data by defining a minimal set of concepts. The primary concept in JSON is the object, which is an unordered collection of name/value pairs, where the value can be any JSON value. There are 4 atomic concepts in JSON common to most programming languages:

  1. string
  2. number
  3. boolean
  4. the special "null" value

Arrays introduce ordered sequences of values, which again, can be a JSON value of one of the 4 previously mentioned JSON types. JSON objects can be nested, but are not commonly deeply nested.

Even though it is a subset of the JavaScript Programming Language, JSON is inherently language independent. Most languages, old and new, have features that map easily to the JSON concepts. For example, hash-map, object, struct, record, and associative array are data types that correlate to the JSON object type, and array, vector and list types correlate to the JSON array type.

Why JSON?

"The less we need to agree on in order to interoperate, the more easily we can interoperate" - Doug Crawford, JavaScript, The Good Parts.

JSON is the data exchange format of choice for the new era of applications. There are several contributing factors to its rise in popularity. Most importantly, the ubiquity of JavaScript. JavaScript is everywhere! It won the browser wars; it runs in the smart phones. More recently, it has become popular for server-side applications with the advent of server-side JavaScript frameworks, such as node.js.

One of the accolades often quoted for JSON is that it is text-based and position-independent, but XML also shares these features. Why then is JSON gaining popularity over XML for APIs? In 2011, Programmable Web reported that 1 in 5 new APIs were choosing JSON over XML; this grew to 1 in 4 by December 2012 (see the Resources section for a link to a blog topic on the choice of JSON over XML). Furthermore, many of the established players, such as Box.net and YouTube are switching from XML to JSON. A few factors contribute to this. First, JSON is simpler and is all about working with objects. It does not attempt to be a document markup language in addition to a data exchange language. This dual purpose of markup and exchange language makes it more difficult for humans to work with XML. Because of its simplicity, JSON is more compact, requiring fewer bits to store, flow across the network, and process on mobile and embedded devices.

It is then not surprising that JSON is also becoming the predominant technology leveraged by NoSQL document stores, such as MongoDB and CouchDB. By providing JSON support in the database tier, we are able to provide the agility gained through schema flexibility to developers of new era applications. Additionally, JSON gives developers greater synergy with their programming language of choice, and allows direct, native storage for the data that is flowing from the mobile device, through the application tier to the disk. This reduces overhead for data transformation and shedding.

Figure 1. DB2 JSON
shows device communicating through JSON script to DB2

What is DB2 JSON?

DB2 JSON is a driver-based solution that embraces the flexibility of the JSON data representation within the context of an RDBMS that provides well-known enterprise features and quality of service. With this offering, users can program their modern application data needs in DB2 using a JSON programming paradigm that is modeled after the MongoDB data model and query language which has arisen as one of the most popular and prolific JSON data stores in the industry. The JSON data is stored in a binary-encoded format called BSON (Binary JSON). BSON is designed to be lightweight, easily traversed and very efficiently encoded and decoded. In addition, MongoDB provides native support for additional data types commonly used by application developers such as date. These extensions have also been added to DB2 JSON support.

Using DB2 JSON, users can interact with JSON data in many ways. First, they can administer and interactively query JSON data using a command line shell. Second, they can programmatically store and query data from Java programs using an IBM provided Java driver for JSON that allows users to connect to their JSON data through the same JDBC driver used for SQL access. Finally, they can use any driver that implements the MongoDB protocol. This allows them to access their DB2 JSON store from a variety of modern languages, including node.js, PHP, Python,and Ruby, as well as more traditional languages such as C, C++, and Perl.

Details for these capabilities are further explained in a series of companion articles as outlined below:


Overview of DB2 JSON Support

The following diagram illustrates the setup and control flow of the JSON API support.

Figure 2. DB2 JSON Overview
shows apps communicating with DB2 engine directly, going thru DB2 JSON wire listener, through JSON API, and also CLP going thru JSON API

DB2 JSON command line

The DB2 JSON command line is a command shell for performing administrative commands for JSON document collections and for running queries and update operations against the JSON collections. It is very similar to the DB2 CLP interface.

For more information on the command line, refer to DB2 JSON Capabilities, Part 2: Using the command-line processor.

DB2 JSON JAVA API

The DB2 JSON Java API provides a set of methods for storing, retrieving and manipulating JSON documents. These methods can be called by native Java applications directly through the API to work with the documents in the database. Since DB2 is the data store, this component translates the operations requested in the method invocations into SQL statements.

For more information on the Java API, refer to "DB2 JSON Capabilities, Part 3: Using the JAVA API".

DB2 for JSON wire listener

The DB2 JSON wire listener is a server application that intercepts the Mongo Wire Protocol. It acts as a mid-tier gateway server between MongoDB applications and DB2. It leverages the DB2 for JSON API in order to interface with DB2 as the data store. A user can execute a MongoDB application written in the desired application programming language (JAVA, NodeJS, PHP, Ruby, etc), or can use the MongoDB CLI to communicate with DB2.

For more information on the wire listener, refer to "DB2 JSON Capabilities, Part 4: Using the Wire Listener".


Conclusion

This article has provided an overview of the DB2 JSON technology which enables developers to write applications using a popular JSON-oriented query language created by MongoDB to interact with data stored in IBM DB2 for Linux, UNIX, and Windows or DB2 for z/OS.

With DB2 JSON support, developers get the best of both worlds: agility with a trusted foundation of DB2. Users do not need to rip and replace their DB2 implementations to be able to leverage agile paradigms in the new era of applications. DB2 10.5 is the first system to provide relational, columnar (DB2 BLU), XML, and JSON data in the same storage engine. You now have the ability to rapidly prototype new applications to complement enterprise systems of record with systems of engagement by leveraging the NoSQL JSON paradigm and flexible schemas, provide fast storage for analytics with DB2 BLU columnar store, alongside their well-known relational applications. At the same time, you preserve the traditional DBMS capabilities, leveraging existing skills and tools.

To link to the download image for the technology, see the Resources section.

Resources

Learn

Get products and technologies

  • Download DB2 to evaluate the DB2 JSON support for yourself.

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Information management on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management, Open source, Java technology, Mobile development
ArticleID=934315
ArticleTitle=DB2 JSON capabilities, Part 1: Introduction to DB2 JSON
publish-date=06202013