1

So, I have a JSON object that contains an array of users who are members of a group. I would like to take all of those users and squish them into one nice string and put that string into a sharepoint list.

I THINK I would use compose, but honestly I've never used it before and I have no idea how. Really, the hope is to convert this:

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects",
  "value": [
    {
      "@odata.type": "#microsoft.graph.user",
      "id": "e3eec502-97a5-47cc-ae81-82c34c4e9b4a",
      "businessPhones": [],
      "displayName": "User one",
      "givenName": "User1",
      "jobTitle": null,
      "mail": "email@email.com",
      "mobilePhone": null,
      "officeLocation": null,
      "preferredLanguage": null,
      "surname": "one",
      "userPrincipalName": "user.one@email.com"
    },
    {
      "@odata.type": "#microsoft.graph.user",
      "id": "ab02d0c4-5770-4a54-95ec-200fb55dfd27",
      "businessPhones": [],
      "displayName": "User two",
      "givenName": "User2",
      "jobTitle": null,
      "mail": "email@email.com",
      "mobilePhone": null,
      "officeLocation": null,
      "preferredLanguage": null,
      "surname": "two",
      "userPrincipalName": "User.two@email.com"
    },
    {
      "@odata.type": "#microsoft.graph.user",
      "id": "15610147-ca81-47c3-bd34-ad046ff9ac46",
      "businessPhones": [],
      "displayName": "User three",
      "givenName": "User3",
      "jobTitle": null,
      "mail": null,
      "mobilePhone": null,
      "officeLocation": null,
      "preferredLanguage": null,
      "surname": "three",
      "userPrincipalName": "user.three@email.com"
    }
  ]
}

To this

User one, User two, User three

Any ideas or resources I can check out? Thanks.

Castrohenge
  • 8,525
  • 5
  • 39
  • 66
Dan Williams
  • 55
  • 1
  • 2
  • 7

2 Answers2

2

This can be achieved using the Parse JSON, Select and Join actions.

The finished flow will be trigger by a button and contain the following actions:

  1. Initialize variable - Initialize a variable with the data we want to manipulate
  2. Parse JSON - Assigns a schema to the data allowing us to more easily access the array
  3. Select - Converts the object array into a string array
  4. Join - Concatenates all the items within the string array

and look like this:

Power Automate flow

Each action needs to be implemented as follows:

1. Initialize variable

First add an initialize variable action with the following values:
  • Name: data
  • Value: The JSON you want to process (as noted in the answer the "@" characters should be removed)

Initialize Variable Settings

2. Parse JSON

You then need to add a Parse JSON action to tell power automate the schema of the data assigned in the initialize variable action. This will allow us to more easily reference the array in the next step. The values should be set to:
  • Content: The data variable
  • Schema:
{
    "type": "object",
    "properties": {
        "odata.context": {
            "type": "string"
        },
        "value": {
            "type": "array",
            "items": {
                "type": "object"
            }
        }
    }
}

Parse JSON action

3. Select

Now add a Select action. This action is normally used to transform one array of objects. However, we can use it to return an array of strings. To do this click the Switch Map to text mode button.

Select Action - Switch Map to text mode

Although you can achieve the desired result by using the expression item()['displayName'], it's possible to construct more complex string by combining the values within the object. For example, we could combine the displayName and mail properties by setting the map value to "@{item()['displayName']} - @{item()['mail']}".

Select Action

4. Join

Finally use a Join action to concatenate the string array produced by the Select action with a specific separator (in your case a comma and space character , ).

Join action

Castrohenge
  • 8,525
  • 5
  • 39
  • 66
0

I did the following ...

Loaded your JSON (minus the @ symbols because PA doesn't like them) into a variable so I can loop over it.

Data

I then created two other variables, one to hold the concatenated string as it's being worked on and the other to hold the end result.

Variables

I then looped over the array of values and pulled out the displayName property and appended it (with a leading comma) to the Concatenated String variable.

Loop

Expression 1 = variables('Data')['value']

Expression 2 = item()['displayName']

The final step is to then remove the leading comma with an expression.

Result

Expression = substring(variables('Concatenated String'), 1)

Result

Result

Flow

Flow

Skin
  • 9,085
  • 2
  • 13
  • 29
  • Welp, had problems. The issue is I'm doing this inside an "apply each" because this is a graph API callthat is looping through multiple groups. So the skeleton is – Dan Williams Jun 17 '22 at 13:22
  • It’s all the same thing, it’s just a matter of adapting my answer to your flow. If you have another specific error, detail it and I might be able to help. – Skin Jun 17 '22 at 14:35
  • 1
    Got it up and running! Checkmark for you! Appreciate! – Dan Williams Jun 21 '22 at 00:59