Wednesday, 28 May 2014

An Intro to JSON in WMB

What is JSON?
JSON (JavaScript Object Notation) is a simple data-interchange format based on a subset of the JavaScript programming language.

How JSON parses or serialises?

JSON parser is supported by Message broker.
Parsing-From bit stream to logical tree
Serialising-From logical tree to bit stream
 The JSON parser interprets a bit stream using the JSON grammar, and generates a corresponding JSON domain logical message tree in the broker. When processing data for output, the JSON serializer generates a JSON formatted bit stream from a JSON domain logical message tree.
Though you can parse,you cannot validate the JSON message as Message modaling of JSON is not supported by WMB
The Data element can be accessed and manipulated from ESQL as JSON.Data, from Java™ as JSON/Data

Is Message Modeling supported for JSON?

The JSON parser and serializer do not support message validation because JSON message modeling is not supported by the broker.


Building a simple JSON flow
I started to practice JSON with a simple flow as depicted below,

Below is the JSON code I used in the Compute node,

SET OutputRoot.JSON.Data.age =  InputRoot.JSON.Data.age + 22;
SET OutputRoot.JSON.Data.address.street  =  'XYZ';
SET OutputRoot.JSON.Data.address.city  =  'ABC';

In HTTPInput node,Message domain in chosen as "JSON".

For HTTP Fault in JSON format,below code is written,

SET OutputRoot.JSON.Data.Fault.ErrorDesc =  'Failure Occured';
SET OutputRoot.JSON.Data.Fault.ErrorCode  =  '1234';

Note 
If you want HTTP Timeout handler to work,you need to use HTTP Embedded listener.If you use HTTP Broker Listener,evenif you have connected HTTP Timeout terminal and handled the Timeout errors,it will not be executed and default SOAP Fault message will be thrown.

I have already explained about how to use Embedded HTTP Listener in my earlier posts.
Below are the commands:
mqsichangeproperties RadBRK -e default -o ExecutionGroup -n httpNodesUseEmbeddedListener -v true
mqsichangeproperties RadBRK    -e default -o HTTPConnector   -n explicitlySetPortNumber -v 7444
To test this,SOAPUI has been used by setting the below highlighted properties,

You can see the response in the right side.