2

I've been working on a workflow in Azure Logic apps, which receives an XML file which I then convert to JSON using json(xml(variables('xmldocument'))) and then I put it in ParseJSON function to which I give the converted JSON as a sample payload to generate the schema. The problem is that I have some timeseries in the file, almost all of them containing many objects. But in the end, there is one timeseries containing only one object. And it creates the problem because the timeseries is treated as an array of objects but the last timeseries ins only one object, no array, and then there is always an error when parsing the JSON. Here is a sample of the file:

<?xml version="1.0" encoding="utf-8"?>
<Document xmlns="blank">
  <mRID>9</mRID>
  <schedule_Time_Period.timeInterval>
    <start>2020-03-20T23:00Z</start>
    <end>2020-03-21T23:00Z</end>
  </schedule_Time_Period.timeInterval>
  <TimeSeries>
    <mRID>c</mRID>
    <businessType>B</businessType>
    <Period>
      <timeInterval>
        <start>2020-03-20T23:00Z</start>
        <end>2020-03-21T23:00Z</end>
      </timeInterval>
      <resolution>P</resolution>
      <Point>
        <position>1</position>
        <quantity>2</quantity>
      </Point>
      <Point>
        <position>2</position>
        <quantity>2</quantity>
      </Point>
    </Period>
  </TimeSeries>
  <TimeSeries>
    <mRID>56</mRID>
    <version>1</version>
    <businessType>A</businessType>
    <Period>
      <timeInterval>
        <start>2020-03-20T23:00Z</start>
        <end>2020-03-21T23:00Z</end>
      </timeInterval>
      <resolution>P1D</resolution>
      <Point>
        <position>1</position>
        <quantity>1.0652</quantity>
      </Point>
    </Period>
  </TimeSeries>
</Document>

Do you have any idea how to deal with it? Thanks for helping me!

Lulka
  • 51
  • 5

2 Answers2

1

Found a pretty easy solution: I just use type: ["array","object"],when specifying the type of the timeseries in the schema.

Lulka
  • 51
  • 5
  • Hi Lulka, it should be a good solution. Since this solution can solve your problem, you can [mark](https://stackoverflow.com/help/someone-answers) yourself answer as "accepted". This can be beneficial to other community members. – Hury Shen Mar 24 '20 at 14:25
0

In this case, I think it is a problem caused by design. When there is only one object in <TimeSeries>, it will be treated as object but not array. For a workaround, we can add another specific record in it. Then it will be treated as array and we can do some operations later to remove this specific record. Otherwise, I don't think the xml() method can match our requirements automatically.

Here is another post which I provided the same solution in the past for your reference.

Hury Shen
  • 14,948
  • 1
  • 9
  • 18