Working with JSON documents with the Java API

You can create, modify, or remove JSON documents that are stored in a Db2 database.

Tip: The Java™ API is no longer the recommended approach for working with JSON data in Db2 for z/OS®. For best results, use SQL and the built-in functions that are supplied with Db2 for z/OS instead. For more information, see Working with JSON documents by using SQL.
The NoSQL capability in Db2 enables JSON documents that are stored in a Db2 database server to be manipulated in the following three ways:
  • The JSON capability for Java API provides a set of methods for storing, retrieving, and manipulating JSON documents. These methods can be called by Java applications directly through the API to work with the documents in the database. Because the Db2 database server is the data store, this component translates the operations that are requested in the method invocations into SQL statements.
  • The JSON command-line interface (CLI) is a command shell for issuing administrative commands for JSON document collections, and for running queries and update operations against the JSON collections. The JSON CLI very similar to the Db2 command line processor.
  • The JSON wire listener is a server application that intercepts the Mongo wire protocol. This wire listener acts as a mid-tier gateway server between MongoDB applications and Db2. It uses the NoSQL for JSON API to interface with the Db2 database server as the data store. You can run a MongoDB application that is written in application programming languages (such as Java, NodeJS, PHP, and Ruby), or you can use the MongoDB CLI to communicate with the Db2 server.

The Java API can also support extra application interfaces, such as the command-line interface and the wire listener.

Figure 1. JSON components in Db2
Begin figure description. A diagram shows the JSON components in DB2. End figure description.
In addition to supporting basic features of the MongoDB query language, the JSON capability also provides extensions that you can use to apply some Db2 database features to JSON documents, such as:
  • Transaction control to group multiple operations into one commit scope
  • Batch processing for multi-row insert operations