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

Convert JSON Body Into Delimited String

Given the below JSON output, how could I end up with a simple string that is delimited by a character, maybe something like this: "The First Label~The Second Label". In the real example, there will be around 100 entries, but same format. Thanks!

 

 

 

{
  "@odata.context": "https://my365.sharepoint.com/_api/v2.1/$metadata#termStores('root')/termGroups('2a6f2ca2-cba8-4c50-aa65-10144b870758')/termSets('53bccced-77aa-47c7-960b-3826191c4730')/terms('d95867d0-3a02-42ac-821d-55c77f90df82')/children",
  "value": [
    {
      "id": "7f50bcc3-7055-4209-b739-0588c99d64fc",
      "isDeprecated": false,
      "childrenCount": 1,
      "createdDateTime": "2022-02-15T17:53:57.567Z",
      "lastModifiedDateTime": "2022-04-11T17:35:19.357Z",
      "labels": [
        {
          "name": "The First Label",
          "isDefault": true,
          "languageTag": "en-US"
        },
        {
          "name": "Label1",
          "isDefault": false,
          "languageTag": "en-US"
        }
      ],
      "descriptions": [],
      "isAvailableForTagging": [
        {
          "setId": "142a45a6-a5d2-487b-a378-5349eaa77ecc",
          "isAvailable": true
        }
      ]
    },
    {
      "id": "8aa8f51f-28bc-4098-abae-ddaf47694933",
      "isDeprecated": false,
      "childrenCount": 2,
      "createdDateTime": "2022-02-15T17:50:43.04Z",
      "lastModifiedDateTime": "2022-04-08T17:54:21.423Z",
      "labels": [
        {
          "name": "The Second Label",
          "isDefault": true,
          "languageTag": "en-US"
        },
        {
          "name": "Label2",
          "isDefault": false,
          "languageTag": "en-US"
        }
      ],
      "descriptions": [],
      "isAvailableForTagging": [
        {
          "setId": "d87322f7-8bda-458f-adf2-c89153182564",
          "isAvailable": true
        }
      ]
    }
  ]
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
WillPage
Power Participant
Power Participant

Input the value property of the JSON into a select with the following expression in the Map field:

WillPage_0-1651184745498.png

Next, use Join to join the result with a comma:

WillPage_1-1651184775683.png

Now in a Compose, do this:

WillPage_2-1651184823184.png

Now another Select. Put the name property in there:

WillPage_3-1651184862628.png

Finally, join the result of that with your chosen character:

WillPage_4-1651184904811.png



The result:

WillPage_5-1651184950134.png

WillPage_6-1651184967167.png

WillPage_7-1651184976969.png

WillPage_8-1651184987419.png

 

WillPage_9-1651185004683.png

 

You could do this with nested apply to each loops and string variables but I prefer to put the effort into avoiding loops where possible. Hope this helps.

View solution in original post

8 REPLIES 8
VictorIvanidze
Community Champion
Community Champion

Have a look at this thread:  https://powerusers.microsoft.com/t5/Building-Flows/Odata-filter-query-with-body-not-working/m-p/1560...

--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.

I am not seeing how that thread would help here

VictorIvanidze
Community Champion
Community Champion

My bad. sorry. 

The proper link is https://powerusers.microsoft.com/t5/Using-Flows/Slow-running-of-Apply-to-each-only-joining-data/m-p/...

--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.

That looks like it could be what I need. I am currently getting this error when it runs. Did I do something wrong? Body is the output from the parse JSON step. "The 'from' property value in the 'select' action inputs is of type 'String'. The value must be an array."

 

SelectScreenshot.png

VictorIvanidze
Community Champion
Community Champion

"value" is an array. Place [0] after ['value'] before ?

--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.
WillPage
Power Participant
Power Participant

Input the value property of the JSON into a select with the following expression in the Map field:

WillPage_0-1651184745498.png

Next, use Join to join the result with a comma:

WillPage_1-1651184775683.png

Now in a Compose, do this:

WillPage_2-1651184823184.png

Now another Select. Put the name property in there:

WillPage_3-1651184862628.png

Finally, join the result of that with your chosen character:

WillPage_4-1651184904811.png



The result:

WillPage_5-1651184950134.png

WillPage_6-1651184967167.png

WillPage_7-1651184976969.png

WillPage_8-1651184987419.png

 

WillPage_9-1651185004683.png

 

You could do this with nested apply to each loops and string variables but I prefer to put the effort into avoiding loops where possible. Hope this helps.

Will, thank you so much for taking the time to write this up. It was exactly the hand holding I needed. Could you let me know if one thing is possible before I mark it as solution? I am looking for the output to be "The First Label~The Second Label" not "The First Label~Label1~The Second Label~Label2". Thanks again!

Replace the formula in the first screen shot there with string(first(item().labels))

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,615)