Note: Documentation for Pivotal GemFire 7.0.x is now available at http://gemfire.docs.pivotal.io/index.html. Please refer to the Pivotal site for the latest and most up-to-date documentation on GemFire 7.0.x. The vFabric GemFire 7.0 documentation site will no longer be updated.

Adding JSON Documents to the GemFire Cache

The JSONFormatter API allows you to put JSON formatted documents into regions and retrieve them later by storing the documents internally as PdxInstances.

vFabric GemFire now supports the use of JSON formatted documents natively. When you add a JSON document to a GemFire cache, you call the JSONFormatter APIs to transform them into the PDX format (as a PdxInstance), which enables GemFire to understand the JSON document at a field level.

In terms of querying and indexing, because the documents are stored internally as PDX, applications can index on any field contained inside the JSON document including any nested field (within JSON objects or JSON arrays.) Any queries run on these stored documents will return PdxInstances as results. To update a JSON document stored in GemFire, you can execute a function on the PdxInstance.

You can then use the JSONFormatter to convert the PdxInstance results back into the JSON document.

JSONFormatter uses a streaming parser (Jackson, JSON processor) to turn JSON documents into the optimized PDX format. You must have added the jackson-core-asl-1.9.9.jar included in $GEMFIRE/lib to your CLASSPATH.

The JSONFormatter class has four static methods that are used to convert JSON document into PdxInstances and then to convert those PdxInstances back into JSON document.

You need to call the following methods before putting any JSON document into the GemFire region:

After putting the JSON document into a region as a PdxInstance, you can execute standard GemFire queries and create indexes on the JSON document in the same manner you would query or index any other GemFire PdxInstance.

After executing a GemFire query or calling region.get, you can use the following methods to convert a PdxInstance back into the JSON format .

For more information on using the JSONFormatter, see the Java API documentation for com.gemstone.gemfire.pdx.JSONFormatter.