BizTalk does not send messages natively in JSON format. However, in recent years, JSON has become the format increasingly widespread.
In order to better use the messaging services of BizTalk limiting as much as possible customizations, normally I use the custom pipeline components for both send and receive operations.
The receive statement is very simple since it is sufficient build a pipeline component that converts JSON formatted message into xml and set a target namespace.
The send statement is slightly more complex because you need to instruct the JSON converter for xml nodes of multiplicity greater than one.
This allows you to correctly generate the JSON array.
To do that, you need work inside the schema, where in any element with multiplicity greater than one, you must specify the attribute json:array equal to true.
We begin by constructing a schema that defines the namespace attribute in JSON.
Once built, you must import it.
Following the XML result.
Then you can define the attribute as JSON array.
Defined the schema, you have to implement the send pipeline component. Below is a code example.
public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg)
if (pInMsg.BodyPart != null)
XmlDocument xmlMessage = new XmlDocument();
foreach (XmlAttribute attribute in xmlMessage.DocumentElement.Attributes)
if (attribute.Name != “xmlns:json”)
string jsonMessage = JsonConvert.SerializeXmlNode(xmlMessage, Newtonsoft.Json.Formatting.None, true);
pInMsg.BodyPart.Data = new MemoryStream(new UTF8Encoding().GetBytes(jsonMessage));
Finally, it is necessary to remove the XML envelope from the WCF layer.