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 Apps / How to create a collec...
Power Apps
Suggested Answer

How to create a collection based on a JSON response

(0) ShareShare
ReportReport
Posted on by 565
Hi All,
 
I have a flow that using Graph API get the users from an given Department.
 
 
 
 
 
 
 
 
 
 
 
The result of this flow is an array called "userarray"
 
{
  "userarray""[{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users(id,displayName,department)\",\"value\":[{\"id\":\"80a60ab4-1555-44e8-a1c3-f86982e06bde\",\"displayName\":\"John Taylor\",\"department\":\"IT Specialists\"},{\"id\":\"a3e5b67-95a3-41a4-b8a8-7159805be72c\",\"displayName\":\"Mike Loma\",\"department\":\"IT Specialists\"},{\"id\":\"c076b123-e560-472b-9dfa-ae8f8b3e2625\",\"displayName\":\"Daniel Anderson\",\"department\":\"IT Specialists\"},{\"id\":\"b772b286-8888-481a-b50a-5a2890710c88\",\"displayName\":\"Homero Chase\",\"department\":\"IT Specialists\"}]}]"
}
 
In Power App, I have a button:
 
Set(varUserArray, HolidaysGetUsersDepartment.Run(txtMyDepartment.Value).userarray);
Set(parsedJSONArray, Table(ParseJSON(varUserArray)));
 
ClearCollect(
    colUsersDepartment,
    ForAll(
        parsedJSONArray,
        {
            DisplayName: Text(Value.displayName),
            Department: Text(Value.department)
        }
    )
)
 
But it is not working, the collection "colUsersDepartment" is empty.
 
Thanks for any help!!
 
Categories:
I have the same question (0)
  • Suggested answer
    Mitanshu Profile Picture
    1,650 Moderator on at
    Can you try the code below:
     
    Set(varUserArray, HolidaysGetUsersDepartment.Run(txtMyDepartment.Value).userarray);
    
    Set(parsedJSON, JSON(varUserArray));
    
    Set(parsedJSONArray, Table(ForAll(Value(parsedJSON), Value)));
    
    ClearCollect(
        colUsersDepartment,
        ForAll(
            parsedJSONArray,
            {
                DisplayName: Text(Value.displayName),
                Department: Text(Value.department)
            }
        )
    );
    
     
    Notes:
    1. JSON(varUserArray): Converts the stringified JSON into a proper JSON object.
    2. Value(parsedJSON): Retrieves the value array from the JSON object (which contains the user details).
    3. Table(ForAll(Value(parsedJSON), Value)): Extracts each item in the array for further processing.
    4. ClearCollect for colUsersDepartment: Builds a collection from the parsed JSON array.

     

    Finally: Use a Label to display intermediate variables like parsedJSON to verify their structure during debugging.
     
     
    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If this post or my previous reply was useful in other ways, please consider giving it Thumbs Up.
     
  • Suggested answer
    Pstork1 Profile Picture
    68,717 Most Valuable Professional on at
    Mitanshu's code will work, but the easier way to do it is use the HTTP Response action to return the array as typed data directly to the collection. The one downside is that it requires a Premium license. If you have Premium I recommend using the HTTP Response. If not the other code will also work.
  • EmilioRoqueta69 Profile Picture
    565 on at
    Hi @Mitanshu,
     
    Thanks for your help!
    I get this error using your code:
    Variable parsedJSON value is blank. 
     
     
     
     
     
    This is the full value of variable "varUserArray" (if it helps!)
     

    [{"@odata.context":"https://graph.microsoft.com/v7.0/$metadata#users(id,displayName,department)","value":[{"id":"40a60ab4-7492-44e4-a7c9-f46942e06bde","displayName":"John Castroman","department":"IT Specialists"},{"id":"a9e7b72e-97a9-47a4-b4a4-7779407be72c","displayName":"Adrian Lloma","department":"IT Specialists"},{"id":"c076b729-e294-472b-9dfa-ae4f4b9e2627","displayName":"Robert Lopez","department":"IT Specialists"},{"id":"b772b246-7407-447a-b70a-ceab624d04e0","displayName":"Victor Rosario","department":"IT Specialists"},{"id":"f60ceb7e-c097-4729-9f9b-4979d7fd7abd","displayName":"Emilio Anderson","department":"IT Specialists"},{"id":"49ce4747-7977-4fce-a470-9b44099cf00c","displayName":"Laura Taylor","department":"IT Specialists"},{"id":"926a744f-69ac-4b44-97a2-7a2490770c44","displayName":"Homero Simpson","department":"IT Specialists"}]}]
  • Suggested answer
    Mitanshu Profile Picture
    1,650 Moderator on at
    Can you try below (slight variation is previous code)

    Can you add some labels at each step for debugging.
     
    Set(varUserArray, HolidaysGetUsersDepartment.Run(txtMyDepartment.Value).userarray);
    
    // Parse JSON string into a usable object
    Set(parsedJSON, JSON(Value(varUserArray)));
    
    // Extract values from the JSON array into a collection
    ClearCollect(
        colUsersDepartment,
        ForAll(
            Table(parsedJSON.value), // Access the "value" array within the JSON object
            {
                DisplayName: Text(ThisRecord.displayName),
                Department: Text(ThisRecord.department)
            }
        )
    );
     
  • EmilioRoqueta69 Profile Picture
    565 on at
    Hi @Mitanshu,
     
    Thanks for the follow-up!
    But I still get an error when paste your last formula.
     
    Did you try to transform this Json example into the collection?
     
    [{"@odata.context":"https://graph.microsoft.com/v7.0/$metadata#users(id,displayName,department)","value":[{"id":"40a60ab4-7492-44e4-a7c9-f46942e06bde","displayName":"John Castroman","department":"IT Specialists"},{"id":"a9e7b72e-97a9-47a4-b4a4-7779407be72c","displayName":"Adrian Lloma","department":"IT Specialists"},{"id":"c076b729-e294-472b-9dfa-ae4f4b9e2627","displayName":"Robert Lopez","department":"IT Specialists"},{"id":"b772b246-7407-447a-b70a-ceab624d04e0","displayName":"Victor Rosario","department":"IT Specialists"},{"id":"f60ceb7e-c097-4729-9f9b-4979d7fd7abd","displayName":"Emilio Anderson","department":"IT Specialists"},{"id":"49ce4747-7977-4fce-a470-9b44099cf00c","displayName":"Laura Taylor","department":"IT Specialists"},{"id":"926a744f-69ac-4b44-97a2-7a2490770c44","displayName":"Homero Simpson","department":"IT Specialists"}]}]
  • EmilioRoqueta69 Profile Picture
    565 on at
    I fixed the flow and now the json response is working.

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard