This post was originally published here

This week while trying to use the BizTalk Server 2016 JSON Schema Wizard to generate an XML schema from a specific JSON file to be sent to a Logic App I got the following error:

Error in JSON Instance File.XMLNodeConverter can only convert JSON that begins with an object. Path ‘’, line 1, position 1.

The JSON file had the following format:

[
  {
    "IntID": 208,
    "ItemLogID": 14255826,
    "Step": "IN",
    "BusinessUnit": "TST",
  },
  {
    "IntID": 209,
    "ItemLogID": 14257419,
    "Step": "IN",
    "BusinessUnit": "TST",
  }
]

Basically, I’m trying to send a list of “objects” that in my case are Locks, to be processed.

Cause

The cause of this “problem” is that a JSON array of objects, it may not make sense in a BizTalk Server XML world as Morten la Cour very well written in this forum. At that sentence, I will add: “at it his being done today”. Because with a few improvements could be smarter and support this type of messages.

Why? The BizTalk
JSON Schema Wizard is a simple and “stupid” converter, it will ask only for you
to provide a root node and a namespace that it will add to the XML Schema and
the XML JSON representation because it will require that information to be able
to uniquely identify this type of message.

But it will not understand what is a “not identified” object array because it needs to give it a Record name in the XML equivalent.

So, that means
that it will not support JSON arrays?

No, it will support JSON arrays if you provide a field name to that array, i.e., instead of having:

[
…
]

You should have:

{
   "field name": [
   …
   ]
}

Solution

If you don’t have the control over that JSON message,
you may need to create a custom pipeline component to add or remove this field
name that will identify the array in the XML equivalent message.

If you have control over the structure of the JSON
message the simple way is to modify the structure of the message to include a
field name to identify the array. Lucky it was my case, so I modify the
original structure descrived above to be:

  {
    "locks": [
    {
      "IntID": 208,
      "ItemLogID": 14255826,
      "Step": "IN",
      "BusinessUnit": "TST",
    },
    {
      "IntID": 209,
      "ItemLogID": 14257419,
      "Step": "IN",
      "BusinessUnit": "TST",
    }
  ]
}

Now, if I try to run the BizTalk JSON Schema Wizard
against this message it will be able to create the JSON Schema.

The post BizTalk JSON Schema Wizard: Error in JSON Instance File.XMLNodeConverter can only convert JSON that begins with an object appeared first on SANDRO PEREIRA BIZTALK BLOG.