Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
JSN Reference

Introduction

JSN provides a C++ implementation of the SAX2 like interface. Our parser 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 parser p6ISax2.

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:

* p6ComPtr<p6IDataStream> cpErrorResult; // -> create this before hand
* p6ComPtr<p6IJSONErrorHandlerInit> cpInitError; // ->
* p6ComPtr<p6IJSONErrorHandler> cpErrorHandler; // -> obtained from the queryInterface call
*
* if (P6SUCCEEDED( err = p6CreateInstance( NULL, CID_p6JSONErrorHandlerInit, VALIDATECOMPTR( p6IJSONErrorHandlerInit, cpInitError ))))
* {
* if (P6SUCCEEDED( err = cpInitError->initialize( pErrorResult )))
* {
* if (P6FAILED( err = cpInitError->queryInterface( VALIDATECOMPTR( p6IJSONErrorHandler, cpErrorHandler )))) return err;
* }
* }
*
* ...->setErrorHandler( pErrorHandler );
*
*