none
JSON Array for single record - biztalk 2013 R2 RRS feed

  • Question

  • HI,

    I need to get the array like below even for the single record.

    {

    "head":{

    "record":[{

    "field1":"value",

    }]

    }

    JSON while converting to XML in pipeline is removing the array for the single record. Can any one please guide how can this be achieved.

    Any inputs are highly appreciated.


    • Edited by Sindhu91 Tuesday, November 7, 2017 3:14 AM
    Tuesday, November 7, 2017 3:13 AM

Answers

  • Hi

    1. The JSON encoder tries to match the input XML with the BizTalk XML Schema (deployed) for the XML to JSON conversion, so if you have the XML bound to a valid XML schema, set the maxoccurs property for the record to unbounded, the JSON encoder will set the array even for a single record.

    2 : If you trying to covert any random XML without any XML schema/ corresponding element in the XML schema then you may need to write a custom pipeline component to do the conversion and set the JSON array for the single occurrence record.


    Tuesday, November 7, 2017 9:15 AM

All replies

  • Hi ,

    I couldn't understand fully.

    Can you confirm what you are expecting/output, currently what is happening/issue you are facing?.

    Refer the below blog to work with JSON Decoder, Encoder. 

    BizTalk Pipeline for JSON

    Working with JSON in BizTalk Server 2013 R2

    Thanks, SMSVikasK


    Tuesday, November 7, 2017 7:15 AM
    Answerer
  • Hi

    1. The JSON encoder tries to match the input XML with the BizTalk XML Schema (deployed) for the XML to JSON conversion, so if you have the XML bound to a valid XML schema, set the maxoccurs property for the record to unbounded, the JSON encoder will set the array even for a single record.

    2 : If you trying to covert any random XML without any XML schema/ corresponding element in the XML schema then you may need to write a custom pipeline component to do the conversion and set the JSON array for the single occurrence record.


    Tuesday, November 7, 2017 9:15 AM
  • There are no arrays in XML, an array in JSON would be a repeating node in XML. 

    So your example would end up as

    <ns0:Rootnodename xmlns:ns0="http://yournamespace">
      <head>
        <record>
          <field1>value</field1>
        </record>
      </head>
    </ns0:Rootnodename>

    If you were to add more items to the array it would be

    <ns0:Rootnodename xmlns:ns0="http://yournamespace">
      <head>
        <record>
          <field1>value</field1>
        </record>
        <record>
          <field2>value2</field2>
        </record>
      </head>
    </ns0:Rootnodename>

    So what is your issue?

    Tuesday, November 7, 2017 11:56 PM