Skip to main content

Notifications

Power Automate - Using Flows
Answered

Convert JSON Object TO Array

Posted on by 13

 

I have the JSON below......

{
  "value": [
    {
      "Email""adele@xxxxxxxxxx.onmicrosoft.com"
    },
    {
      "Email""sydney@xxxxxxxx.OnMicrosoft.com"
    },
    {
      "Email""admin@xxxxxxxxxx.onmicrosoft.com"
    }
  ]
}

 

How can I get the array below from the JSON above?
[

      "adele@m365x685435.onmicrosoft.com"
      "sydney@M365x685435.OnMicrosoft.com"
      "jons@m365x685435.onmicrosoft.com"
]
  • RV-13111419-0 Profile Picture
    RV-13111419-0 4 on at
    Convert JSON Object TO Array
    if your object has known field names, then use Hill's answer.
     
    In my case I needed to convert an object into a key/value pair array with dynamic keys so suggested answers didn't work for me.
     
    If your object has dynamic field names which you don't know up front, use Sroo's example. Sroo's example basically parses the raw JSON (convert to string and remove {} ) and splits it based on comma. Then iterate over the resulting array and do another split based on : character. Now your first index has the fieldname (key) and the second index has the value. Then you can use that to do whatever, which in my case was adding a key-value object into a an array.
  • ManelPereira98 Profile Picture
    ManelPereira98 18 on at
    Re: Convert JSON Object TO Array

    Thank you this is the ONLY Correct way to perform this. The append to variable method is WAY TOO INNEFICIENT. I wish I could Upvote x1000.

  • Hill Profile Picture
    Hill 12 on at
    Re: Convert JSON Object TO Array

    Well if you're only looking at the title of the initial question you're correct, but the provided example of Harbie contained JSON objects within an array within a JSON object. 

    If you look at zapower's example It looks like you and him are trying to do the same thing, (for which the select action will not work).
    But i don't know what exactly your desired result is, and i don't see an easy way to do it dynamically.


    If you just hardcode the names of the Objects you could use a compose action with the following content to get an Array out of zapowers example:

     

     

    createArray(outputs('Compose_JSON_Objects')?['7ee5fb1d-fef6-483e-84e6-9b4d960f2d80'],outputs('Compose_JSON_Objects')?['3022a04a-5248-4bc0-af78-39f0f48ae292'],outputs('Compose_JSON_Objects')?['5bd1d5b7-119a-4e90-862c-756b8e13c3fc'])

     

     

    So theoretically you could first list all the names of the desired Objects, and then access them with said list.

    Edit: 
    the step "Compose_JSON_Objects" from above is this here:
    Hill_0-1714374172145.png

  • RBoneck Profile Picture
    RBoneck 405 on at
    Re: Convert JSON Object TO Array

    I'm not sure I understand your solution. The question was how to get an array out of the object given, but your example is how to make an array out of a different array. The select action can't even accept an object in the from property. 

    Boneckrh19_0-1713992885806.png


    How would you convert an object into an array?

  • zapower Profile Picture
    zapower 4 on at
    Re: Convert JSON Object TO Array

    Before I create a new post, maybe someone here can help me.

    I also try to convert JSON Object to Array, i tired a lot of different approaches but everything seems to fail. 

     

    Here my JSON: 

    {
    "7ee5fb1d-fef6-483e-84e6-9b4d960f2d80": {
    "last_changed": 1703081408,
    "last_checked": 1704789923,
    "last_error": false,
    "title": "Keynote",
    "url": "http://abc.de",
    "viewed": true
    },
    "3022a04a-5248-4bc0-af78-39f0f48ae292": {
    "last_changed": 1704119225,
    "last_checked": 1705312960,
    "last_error": false,
    "title": "1Password",
    "url": "http://abc.de",
    "viewed": true
    },
    "5bd1d5b7-119a-4e90-862c-756b8e13c3fc": {
    "last_changed": 1703082231,
    "last_checked": 1705310059,
    "last_error": false,
    "title": "7-Zip",
    "url": "http://abc.de",
    "viewed": true
    },
    }
     
    Thank you for any input. 
  • Hill Profile Picture
    Hill 12 on at
    Re: Convert JSON Object TO Array

    Hi mgisbert
    Have you tried my way of using the select action?
    For me this one seems to work even with null values

    Hill_0-1703163698990.png

     

  • mgisbert Profile Picture
    mgisbert 71 on at
    Re: Convert JSON Object TO Array

    I've done this and I realised the Append into array does not allow null values. How could this be done if some of the values coming from the JSON object can be null? 

    Thanks! 

  • bruno9d Profile Picture
    bruno9d 3 on at
    Re: Convert JSON Object TO Array

    This is a much simpler and clever way I would say.

     

    Also If you need an array for each step inside a loop in parallel mode (the problem that I was solving) you need to use this option instead of looping and appending to an array variable because the array will be filled in parallel and you will get messed up values since it's a global variable and in contrast the Select action outputs a context variable for each loop interaction that works fine.

  • Hill Profile Picture
    Hill 12 on at
    Re: Convert JSON Object TO Array

    Hi
    My favorite way is to use a select action like this:

    Hill_1-1679478026221.png

    From:

    outputs('Compose_JSON_Array')?['value']

     

    Map: you have to switch to text mode, delete the brackets etc. and enter the Expression 

    item()?['Email']

     

    Like in the Picture:

    Hill_2-1679478049478.png


    This should result in this:

    Hill_3-1679478093309.png

  • TsarCannon Profile Picture
    TsarCannon 7 on at
    Re: Convert JSON Object TO Array

    wow man! Gonna try rn

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,532

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,050

Leaderboard

Featured topics

Restore a deleted flow