title: Mule 4: Transforming SQL XML object to JSON
body: <p>I am getting SQLXML resultset as an output of MS SQL stored procedure called from the Database Execute Stored Procedure shape.</p>
  <p>The SQLXML resultset looks like:</p>
  <pre><code>&lt;xmlcontent&gt;
     &lt;field1&gt;val1&lt;/field1&gt;
     &lt;field2&gt;val2&lt;/field2&gt;
     &lt;field3&gt;val3&lt;/filed3&gt;
  &lt;/xmlcontent&gt;
  &lt;xmlcontent&gt;
     &lt;field1&gt;val1&lt;/field1&gt;
     &lt;field2&gt;val2&lt;/field2&gt;
     &lt;field3&gt;val3&lt;/filed3&gt;
  &lt;/xmlcontent&gt;
  &lt;xmlcontent&gt;
     &lt;field1&gt;val1&lt;/field1&gt;
     &lt;field2&gt;val2&lt;/field2&gt;
     &lt;field3&gt;val3&lt;/filed3&gt;
  &lt;/xmlcontent&gt;
  </code></pre>
  <p>However, the payload is a bit weird, as it contains the XML output of length 2033 and then repeated as the array element until the payload is exhausted. The transform shape output with the just payload shows:</p>
  <pre><code>{
    &quot;resultSet1&quot;: [
      {
        &quot;XML_F52E2B61-18A1-11d1-B105-00805F49916B&quot;: &quot;&lt;xmlcontent&gt;&lt;field1/&gt;&lt;field2/&gt;&lt;field3/&gt;&quot; --this content is of size 2033 max
      },
      {
        &quot;XML_F52E2B61-18A1-11d1-B105-00805F49916B&quot;: &quot;&lt;/xmlcontent&gt;&lt;xmlcontent&gt;&lt;field1/&gt;&lt;fiel&quot; --this content is of size 2033 max
      },
      {
        &quot;XML_F52E2B61-18A1-11d1-B105-00805F49916B&quot;: &quot;d2/&gt;&lt;field3/&gt;&lt;xmlcontent&gt;&quot;
      }
    ]
  }
  </code></pre>
  <p>I am thinking of using another transform shape to append the values of &quot;XML_F52E2B61-18A1-11d1-B105-00805F49916B&quot; from the resultset1 array and then transforming to JSON. Is there a way in data weave to simplify this approach to get final JSON output as below?</p>
  <pre><code>    [
     {
        &quot;field1&quot;: &quot;val1&quot;,
        &quot;field2&quot;: &quot;val2&quot;,
        &quot;field3&quot;: &quot;val3&quot;
     },
     {
        &quot;field1&quot;: &quot;val1&quot;,
        &quot;field2&quot;: &quot;val2&quot;,
        &quot;field3&quot;: &quot;val3&quot;
     },
     {
        &quot;field1&quot;: &quot;val1&quot;,
        &quot;field2&quot;: &quot;val2&quot;,
        &quot;field3&quot;: &quot;val3&quot;
     }
  ]
  </code></pre>