Sandbox Tutorial for JSON

This section provides a tutorial that will help you build a Java application using the MapR-DB JSON Java API library.

This tutorial is an implementation of the Open JSON Application Interface (OJAI) API library. Basic information about using the MapR-DB Shell (JSON Tables) utility for JSON tables is also included in this document.

About OJAI

The MapR-DB JSON Java API library leverages MapR-DB support for OJAI in many areas, including:

  • Tables
  • Sub-documents
  • Efficient access to data
  • Large document support
  • Security

Key features of the API library include:

  • APIs for manipulating JSON documents
  • Extensions to the Hadoop ecosystem:
    • Efficient parsing of large files
    • MapReduce integration

JSON Support

MapR-DB, in addition to its support of the key-value model (column family), now offers a Document Model. This means that applications can use a JSON document to represent data. JSON is built on two structures:

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
A document looks like this:
{
    "_id" : "001",
    "first_name" : "John",
    "last_name" : "Doe",
    "age" : 45,
    "email" : "jd@mydoc.com",
    "interests" : ["sports", "movies"],
    "address" : {
        "street" : "1015 Main Street",
        "city" : "San Jose",
        "state" : "CA",
        "zip" : "95106"
    }
}

MapR-DB stores the documents in tables. An interesting aspect of MapR-DB JSON is that inside a table, documents can have a different structure.

Documents inside MapR-DB must have a unique identifier stored in the _id field.

MapR-DB does not store the documents as a whole in a single location. Instead, MapR-DB creates fields for each attribute and nested documents/attributes. This allows MapR-DB to access the information very efficiently. When you read, for example using projection, or when you edit a document, only the necessary fields will be modified. MapR-DB can store very large documents, for example, multi-GB documents, if the application requires it.

Prerequisites