from BizTalk I have to send an JSON file which looks like this.
[
{
"attr": {
"b587d548-8aa6-42b7-b292-0f3e13452c35": {
"1": "-2.073420455529934786"
}
},
"guid": "80974561-a449-4a94-8b3e-970822b84406",
"anotherGuid": "05060c4c-f0af-46b8-810e-30c0c00a379e",
"lastModified": "2019-11-09T01:44:34.157Z",
"attributes":
{
"4": "2019-11-05T20:30:57.6Z",
"8": "6",
"10": "8",
"13": "7",
"27": "3",
...
},
...
}
]
In a BizTalk Schema I can't define something like this. The Guid
in attr
and the number attribute names in attributes
aren't fix and could be other values.
I have the idea to implement a custom pipeline component which converts the BizTalk XML to Output JSON. But I have no idea how to solve the problem with the names of the Attributes because these are no valid XML names.
What might be the most elegant kind to solve this problem?
Thanks in advance.
UPDATE with more information
To get an JSON
like above the XML
has to be look like which is invalid
<root>
<element>
<anotherGuid>05060c4c-f0af-46b8-810e-30c0c00a379e</anotherGuid>
<attr>
<b587d548-8aa6-42b7-b292-0f3e13452c35>
<1>-2.073420455529934786</1>
</b587d548-8aa6-42b7-b292-0f3e13452c35>
</attr>
<attributes>
<10>8</10>
<13>7</13>
<27>3</27>
<4>2019-11-05T20:30:57.6Z</4>
<8>6</8>
</attributes>
<guid>80974561-a449-4a94-8b3e-970822b84406</guid>
<lastModified>2019-11-09T01:44:34.157Z</lastModified>
</element>
</root>
To get a valid XML
I have to change the invalid elements, i.e. instead of <4 />
maybe <e4 />
, <element name="4" />
or something like this. Then a parser (or something else?) has to map this XML
element to the correct JSON
one.
I find a solution for this problem but not in the originally wanted kind.
The data are received from a stored procedure. This I get as XML and wanted to convert this to the JSON from the question. Because a JSON like this could not be created from a corresponding XML (this would be not well-formed) I don't think that there is a clean solution for these issue. I let the question open just in case there might be a good possibility.
Now I solved it in the following way. I have a stored procedure which delivers the data as JSON now. Because BizTalk works only with XML this JSON is included in an XML structure. Then I wrote a custom pipeline component which extract the JSON from the XML and transmit it out of BizTalk to the destination system. So I get the JSON structure without serializing from XML.
This is more a workaround but something which works good.