Handle Array/List Json messages in BizTalk Receive Pipeline

This blog is to explain how to handle below requirements in BizTalk Receive Pipeline.

  1. Handle Non-List/Array json messages
  2. Handle List/Array json messages
  3. Remove special characters before Json Decoder pipeline stage

Let’s discuss these points.

  1. Handle Non-List/Array json messages

By default, BizTalk Receive Pipeline Json Decoder can convert the Json message to Xml message.

Example:

{

    “ForeignTax”: 12.5,

    “AdditionalPremium”: 20

}

2. Handle List/Array json messages

By default, BizTalk receive pipeline Json Decoder cannot convert Array/List Json messages to Xml format.

Example:

[

    {

        “Id”: 94,

        “LineOfBuinsinesses”: [

            {

                “Id”: 1,

                “Description”: “abc”,

                “Type”: 1

            },

            {

                “Id”: 2,

                “Description”: “def”,

                “Type”: 2

            },

            {

                “Id”: 3,

                “Description”: “ghi”,

                “Type”: 2

            }

        ]

    }

]

In order to handle this kind of json messages, we need to add one Root element to the message and this can be done using custom pipeline. You can download the custom pipeline code from below link.

DownLoad

We need to add this pipeline to Receive pipeline decode stage and deploy the application.

You need to supply the RootName parameters from Pipeline properties in BizTalk admin console.

1.png

 

In the above screenshot, you need to provide RootNode under Decode Stage.

After executing this receive pipeline Enhance JSON Stage, your json message looks like something below and this message can be handled by JSON Decoder.

 

{“Details”: [

    {

        “Id”: 94,

        “LineOfBuinsinesses”: [

            {

                “Id”: 1,

                “Description”: “abc”,

                “Type”: 1

            },

            {

                “Id”: 2,

                “Description”: “def”,

                “Type”: 2

            },

            {

                “Id”: 3,

                “Description”: “ghi”,

                “Type”: 2

            }

        ]

    }

]}

 

Also, you can use the same pipeline for both List and Non-List messages, only thing you have to do for Non-list message is that you no need to supply any Root parameter.

3. Remove special characters before Json Decoder pipeline stage

If you want to remove some special characters in the Json message, you can use some regular expression in the custom Pipeline code.

Example:

string invalidCodeRegEx = @”[\\][u][0-9]{4}|\\b”;

                text = System.Text.RegularExpressions.Regex.Replace(text, invalidCodeRegEx, “”);

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s