web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Parsing a Json array w...
Power Automate
Unanswered

Parsing a Json array with Dynamic Key Values

(0) ShareShare
ReportReport
Posted on by 9

hey guys;

 

Im really struggling to export an API call that includes Dynamic ids - I've run through a heap of other examples (Converting to to an XML and trying to parse through it that way, normal json parsing etc) & I'm not having much luck.

 

example of my output:

 

{
"1": {
"id": 1,
"pressure": 0,
"temperature": 282.15,
"atmospheric": 123,
"refdate": "Sun, 12 Feb 2023 19:40:27 GMT",
"tyreid": null,
"vehicleid": null,
"position": null,
"tyresettingid": null,
"ptarget": null,
"palarm": 0,
"talarm": 0,
"strangerptarget": null,
"strangerpalarm": 0,
"strangertalarm": 0,
"triggered": 1,
"fastmode": 0,
"error": 0,
"": 0,
"tagtimeout": true,
"alarmtimeout": true
},
"2": {
"id": 2,
"pressure": 0,
"temperature": 123,
"atmospheric": 123,
"refdate": "Sun, 12 Feb 2023 20:40:45 GMT",
"tyreid": null,
"vehicleid": null,
"position": null,
"tyresettingid": null,
"ptarget": 123,
"palarm": 0,
"talarm": 0,
"strangerptarget": null,
"strangerpalarm": 0,
"strangertalarm": 0,
"triggered": 1,
"fastmode": 0,
"error": 0,
"": 0,
"tagtimeout": true,
"alarmtimeout": true
}}

 

I have both a Blank field (near the end, with a 0 value) and an id that is included in my key... so a traditional json schema does not work - and PowerAutomate does not allow pattern matching from the tests I have done.

 

Any suggestions? I just need this exported in CSV.

Categories:
I have the same question (0)
  • Sundeep_Malik Profile Picture
    6,484 on at

    Hey @Macmy034 

     

    It worked for me, not sure why its not working for you.

    My flow (Added your data in a compose, then used parse json and then used another compose for that blank field):

    Sundeep_Malik_1-1676349288450.png

     

    Output:

    Sundeep_Malik_0-1676349225118.png

     

  • Macmy034 Profile Picture
    9 on at

    What Json Schema did you use?

     

    I can have anywhere from 1 to 300+ values where it has 

    "1" for each object... Did you hardcode the 1...2... in the schema or have something dynamically assign them?

  • Sundeep_Malik Profile Picture
    6,484 on at

    @Macmy034 

    I didn't hard code anything, I just took default of everything. Do you want me to paste the schema here?

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Hopefully this is what you're looking for. That's some horrible JSON you have 🙂

     

    Below is the full flow. I'll go into each of the actions.

    grantjenkins_0-1676352297158.png

     

    JSON is a Compose that contains your JSON data. I'm not sure where your data is coming from.

    grantjenkins_1-1676352494539.png

     

    Compose uses the following expression to strip out parts of your data so we can prepare it into a proper JSON format for your CSV.

    //You would replace outputs('JSON') with whatever contains your JSON
    
    split(slice(string(outputs('JSON')), 1, lastIndexOf(string(outputs('JSON')), '}')), '}')

     

    Filter array takes the output from the Compose and filters out any empty rows (the last row) using the following expression.

    trim(item())

    grantjenkins_2-1676354178022.png

     

    Select uses the output from the Filter array and appies the following expression to complete the transformation of the data so we get an array of objects that we can use to create the CSV.

    json(concat(slice(item(), indexOf(item(), '{')), '}'))

    grantjenkins_3-1676354969276.png

     

    This will provide the following JSON output.

    [
     {
     "id": 1,
     "pressure": 0,
     "temperature": 282.15,
     "atmospheric": 123,
     "refdate": "Sun, 12 Feb 2023 19:40:27 GMT",
     "tyreid": null,
     "vehicleid": null,
     "position": null,
     "tyresettingid": null,
     "ptarget": null,
     "palarm": 0,
     "talarm": 0,
     "strangerptarget": null,
     "strangerpalarm": 0,
     "strangertalarm": 0,
     "triggered": 1,
     "fastmode": 0,
     "error": 0,
     "": 0,
     "tagtimeout": true,
     "alarmtimeout": true
     },
     {
     "id": 2,
     "pressure": 0,
     "temperature": 123,
     "atmospheric": 123,
     "refdate": "Sun, 12 Feb 2023 20:40:45 GMT",
     "tyreid": null,
     "vehicleid": null,
     "position": null,
     "tyresettingid": null,
     "ptarget": 123,
     "palarm": 0,
     "talarm": 0,
     "strangerptarget": null,
     "strangerpalarm": 0,
     "strangertalarm": 0,
     "triggered": 1,
     "fastmode": 0,
     "error": 0,
     "": 0,
     "tagtimeout": true,
     "alarmtimeout": true
     }
    ]

     

    Create CSV table takes in the output from Select. Or you could specify just the fields you want. The empty property will just create a column in your CSV that doesn't have anything in the Header column.

    grantjenkins_4-1676355709840.png

     

    Send an email then attaches the CSV table.

    grantjenkins_5-1676355745115.png


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

  • Macmy034 Profile Picture
    9 on at

    Thank you so much Grant!

     

    The stripping of elements in the correct order and how to combine it all was doing my head in - In python its easy enough, but doing it in power automate was sending me crazy!

     

    The data comes from an API call - we're usually requested to do it in Power Automate so people can debug down the line if anything occurs, asking someone to fire up an IDE when they have no idea how to code can make things challenging.

     

    I really appreciate your help, this is absoloutely perfect!!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard