cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stevenls
Helper III
Helper III

Parse JSON - How to pull a variable from the output

Hi there,

 

I have a flow where I am successfully parsing the JSON of the message attachment section of a MessageCard, but I am unsure how to extract part of the string.

 

This is the 'OUTPUTS' from the Parse JSON

[
  {
    "id": "f0b9ba20989b4363aca847288a4612fc",
    "contentType": "application/vnd.microsoft.teams.card.o365connector",
    "contentUrl": null,
    "content": "{\r\n  \"summary\": \"Steven.Lees-Smith@al.com.au\",\r\n  \"text\": \"\",\r\n  \"title\": \"AL0110182 - Useracct leave script broken.\",\r\n  \"themeColor\": \"0076D7\",\r\n  \"sections\": [\r\n    {\r\n      \"text\": \"\",\r\n      \"facts\": [\r\n        {\r\n          \"name\": \"Created:\",\r\n          \"value\": \"<p>06/27/2019 11:54:57</p>\"\r\n        },\r\n        {\r\n          \"name\": \"Customer:\",\r\n          \"value\": \"<p>Josh Lewis</p>\"\r\n        },\r\n        {\r\n          \"name\": \"Description:\",\r\n          \"value\": \"<p>Hey Kev, </p>\\r\\n\\n\\n\\r\\n<p>As we spoke about leaver script is broken, please fix! </p>\\r\\n\\n\\n\\r\\n<p>Thanks,\\nJosh.</p>\"\r\n        },\r\n        {\r\n          \"name\": \"Technician:\",\r\n          \"value\": \"<p>Steven Lees-Smith</p>\"\r\n        }\r\n      ],\r\n      \"title\": \"\",\r\n      \"activityTitle\": \"\",\r\n      \"activitySubtitle\": \"\",\r\n      \"activityText\": \"\",\r\n      \"markdown\": true,\r\n      \"startGroup\": false\r\n    }\r\n  ],\r\n  \"potentialAction\": [\r\n    {\r\n      \"actions\": [\r\n        {\r\n          \"targets\": [\r\n            {\r\n              \"os\": \"default\",\r\n              \"uri\": \"https://servicedesk.al.com.au/CherwellClient/Access/incident/AL0110182\"\r\n            }\r\n          ],\r\n          \"@type\": \"OpenUri\",\r\n          \"@id\": \"4ce80739-a54c-4034-bb91-7b63a80ab5f7\",\r\n          \"name\": \"Go to Full Record\",\r\n          \"isPrimaryAction\": false\r\n        }\r\n      ],\r\n      \"@type\": \"ActionCard\",\r\n      \"@id\": \"2a26ef43-d190-4f96-b62e-e1faeccccc15\",\r\n      \"name\": \"View in Cherwell\",\r\n      \"isPrimaryAction\": false\r\n    }\r\n  ]\r\n}",
    "name": null,
    "thumbnailUrl": null
  }
]

In the Content section I want to pull out this;

\"title\": \"AL0110182 - Useracct leave script broken.\"

 

so I can store the title as a variable and then use it in a message.  I am just not sure of the next step to extract that section of text into a variable. 

1 ACCEPTED SOLUTION

Accepted Solutions

Actually I just sorted it out.

I set a variable at the top of the flow.

Parse out the JSON to end up with schema, using the apply to each step I use the output from the previous step and append the parsed JSON to a string variable.

I then use a combination of first and last to get to the 'title' entity I need and then turn the output of the compose into a variable.

Using this approach I have actually stripped out the URL back the originating system to allow after the user is mentioned (I pulled the email also) they can click a link and open up the incident in Cherwell.

Cheers.

View solution in original post

6 REPLIES 6
efialttes
Super User III
Super User III

Hi!

I looks like Content attribute was originally JSON but shown in string format. If so, I would try to add a second 'Parse JSON' action block (let's call it 'Parse JSON 2') and assign the following expression as its input:

 

body('Parse_JSON')['content']

 

 

Then you can access 'title' attribute by means of the following expression...

 

body('Parse_JSON_2')['title']

 

...or, by selecting 'title' from the dynamic content menu.

 

Hope this helps

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



v-alzhan-msft
Community Support
Community Support

Hi @stevenls ,

 

Could you please share a screenshot of the Configuration of your flow?

As @efialttes  said, the provided output is a string text, could you please run the flow to share the full output from the Parse JSON action?

 

Best regards,

Alice   

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hey there,

I am not quite sure based on the reply what to put in the schema of the second parse.

Here is a screenshot of the flow and the output.

Parse2.JPGoutput.JPG

The arrow pointing to the 'Content' is where title is and a few other strings I want to attempt to get, just need to get one right first.

 

Not sure what to do with this

body('Parse_JSON')['content']

 

Thanks

 

 

 

As a result of this substring;

substring(variables('JSONTitle'),indexOf(variables('JSONTitle'),'AL0'))
 
I have this

 

AL0110182 - Useracct leave script broken.",
"themeColor": "0076D7",
"sections": [
{

 

I suppose I just need to stop the substring at the " and that is my title done.
"text": "",
"facts": [
{

Hi @stevenls ,

 

Sorry for I'm afraid that there is no any way to achieve your requirement to get the value from the output since it isn't a valid JSON.

 

Best regards,

Alice   

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Actually I just sorted it out.

I set a variable at the top of the flow.

Parse out the JSON to end up with schema, using the apply to each step I use the output from the previous step and append the parsed JSON to a string variable.

I then use a combination of first and last to get to the 'title' entity I need and then turn the output of the compose into a variable.

Using this approach I have actually stripped out the URL back the originating system to allow after the user is mentioned (I pulled the email also) they can click a link and open up the incident in Cherwell.

Cheers.

View solution in original post

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,492)