Search code examples
jsonbiztalkpipeline

BizTalk JSON Receive Pipeline Decoder - Does it have to add a root wrapper element?


The BizTalk decoder pipeline component displays values of RootNode and RootNodeNamespace in the configuration of the pipeline (in BizTalk Admin Console).

When I don't specify the root, it blows up and says: "Reason: Root node name is not specifed in Json decoder properties"

When I do specify a root, it gets added. But why does it need to add a root if I have a "root" in my JSON?

Example JSON:

 { "AppRequest": { 
       "DocumentName": "whatever", 
       "Source": "whatever" 
       }
   }

So I would like to use the JSON above, and have a schema with a root of "AppRequest". But if I drop a file with this JSON, and specify AppRequest as the Root, then I get an extra AppRequest wrapper around the AppRequest I already have.

To me this is odd behavior, if you want to have a schema/contract first approach. I might agree on the JSON with my trading partner, then later build the schema in BizTalk; and now I'm locked in to a schema with a root, and an element under it with the same name again.

Further, the person building the JSON is probably deserializing a class, so the class name will be the "root" of that JSON file.

Yes, I could write my own decoder pipeline components ... just trying to figure out why they did it the way they did it, or if I missing something obvious.


Solution

  • Yes, a root node and namespace is required by the JSON Decoder.

    There is a reason for this. JSON does not require the equivalent of a root node while XML does require a root node. Making it a required property eliminates any ambiguity about the conversion. It's just that simple.

    Since you will typically need to use the XML Disassembler also, you can strip the JSON Encoder added rood node by essentially Debatching the content with an Envelope Schema matching the JSON Encoder root node. You can remove the Xml Namespace as well which is also a good idea.