cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

Conditionally tidying a JSON response containing nested arrays

Hi all,

 

I am trying to tidy a JSON response from a GET request. One of the returned keys contains a nested array, but I don't need any of the information from this field. I would like to select only values from the response which have a date which is greater than a specified date (in this example, 20 January 2020, or 2020-01-20), and for which the status is false.

 

The response comes in the following format:

 

 

[
  {
    "id": 1,
    "description": "ABC",
    "status": true,
    "date": "2020-01-27",
    "process": [
      {
        "stage": 1,
        "status": false
      },
      {
        "stage": 2,
        "status": false
      },
      {
        "stage": 3,
        "status": false
      }
    ]
  },
  {
    "id": 2,
    "description": "DEF",
    "status": false,
    "date": "2020-01-25",
    "process": [
      {
        "stage": 1,
        "status": true
      },
      {
        "stage": 2,
        "status": false
      },
      {
        "stage": 3,
        "status": true
      }
    ]
  },
  {
    "id": 3,
    "description": "GHI",
    "status": false,
    "date": "2020-01-18",
    "process": [
      {
        "stage": 1,
        "status": false
      },
      {
        "stage": 2,
        "status": true
      },
      {
        "stage": 3,
        "status": false
      }
    ]
  },
  {
    "id": 4,
    "description": "JKL",
    "status": false,
    "date": "2020-01-23",
    "process": [
      {
        "stage": 1,
        "status": true
      },
      {
        "stage": 2,
        "status": true
      },
      {
        "stage": 3,
        "status": true
      }
    ]
  },

 

 

 

Using the logic described above, I would like to reduce this to the following:

 

 

 

[
  {
    "id": 2,
    "description": "DEF",
    "date": "2020-01-25"
  },
  {
    "id": 4,
    "description": "JKL",
    "date"; "2020-01-23"
  }
]

 

 

 

I have tried to do this using both a apply to all function and a select function, but both of these appear to struggle with the nested array.

 

Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User III
Dual Super User III

You  can do this with a combination of a Parse JSON, filter Array and Data Select statement.  Use the select to get rid of the embedded array and filter array to filter the results.

image.png



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

3 REPLIES 3
Super User III
Super User III

This flow does what you want:

https://ibb.co/yqjtCVT

Cleaup-JSON.jpg

Explanation:

  • First filter reduces results to status = false.
  • Second filter reduces results to date greater than 2020-01-20.
  • Select reformats the JSON to remove the parts you don't want.

It produces the result:

[
  {
    "id": 2,
    "description": "DEF",
    "date": "2020-01-25"
  },
  {
    "id": 4,
    "description": "JKL",
    "date": "2020-01-23"
  }
]

Should you get stuck, I have exported the flow, which you can download from here:

https://www.tachytelic.net/wp-content/uploads/CleanJSON_20210124150329.zip

 

Hope this helps.

Dual Super User III
Dual Super User III

You  can do this with a combination of a Parse JSON, filter Array and Data Select statement.  Use the select to get rid of the embedded array and filter array to filter the results.

image.png



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

New Member

Thanks both -- this did the trick.

Helpful resources

Announcements
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (35,160)