JSON Implementation

Introduction

P6R's JSON parser provides a C++ implementation of the SAX2 like interface. Our parse implemenation is designed to be high performance and to directly support a streaming IO model. The parser can be invoked with the entire JSON document in one buffer, or the JSON document feed into the parser a chunk at a time over multiple calls. This streaming IO model is implemented via the P6R::p6IDataStream interface (see p6datastream.h). This interface allows chaining of components (e.g., filters, sources and sinks). To assist a developer in debugging a detailed parse trace can be turned on programaticaly. Note that our JSON parser is very similar to our XML SAX2 Implementation.

JSON Parser, XPATH, and XSLT

Details of our JSON support can be found at the following URLs:

A SAX-like Parser for JSON - https://www.p6r.com/articles/2008/05/22/a-sax-like-parser-for-json/

XSLT and XPath for JSON - https://www.p6r.com/articles/2008/05/06/xslt-and-xpath-for-json/

<xsl:output method=’json’/> - https://www.p6r.com/articles/2008/11/02/xsloutput-methodjson/

Includes

Interfaces

The Lifetime of P6JSONSTRING pointers

P6JSONSTRINGs can point into application provided or JSON internal buffers. P6JSONSTRING values are ONLY valid during a callback into an application written content handler. An application that wants to keep a copy of the string MUST make a copy during a callback. This way an application has total control of how it manages its own memory and related performance concerns.

Note that in the standard SAX2 definition an application defines a set of 'handlers' to process events (e.g., startDocument). These handlers are the aforementioned callback routines. See the P6R::p6IJSONReader interface for how to register these handlers.

A Default Implementation of p6IJSONErrorHandler

An application using P6R's JSON parser can define and register its own implementation of the P6R::p6IJSONErrorHandler. However, P6R has provided a default component implementation of this interface. In the file, p6jsonerrorhandler.h is a definition of the component: P6R::p6IJSONErrorHandlerInit. This component takes a P6R::p6IDataStream as an output destination. To use p6IJSONErrorHandlerInit component follow the following code snipet:

 p6IDataStream           *pErrorResult;     // -> create this before hand
 p6IJSONErrorHandlerInit *pInitError;       // ->
 p6IJSONErrorHandler     *pErrorHandler;    // -> obtained from the queryInterface call

 if (P6SUCCEEDED( err = p6CreateInstance( NULL, CID_p6JSONErrorHandlerInit, VALIDATEIF( p6IJSONErrorHandlerInit, &pInitError )))) 
 {
     if (P6SUCCEEDED( err = pInitError->initialize( pErrorResult ))) 
     {
         if (P6FAILED( err = pInitError->queryInterface( VALIDATEIF( p6IJSONErrorHandler, &pErrorHandler )))) return err;
     }
 }

 ...->setErrorHandler( pErrorHandler );
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Copyright © 2004 - 2010 P6R Inc. - All Rights Reserved.