Parse JSON elements of a list returned from a multi-choice column in Power Automate/MS flow
-
17-02-2021 - |
Pregunta
I am calling the SP API to get the version history of an item in my list as follows:
_api/web/lists/getbytitle('@{triggerBody()?['SPListName']}')/items(@{triggerBody()?['SPListID']})/versions?$top=20
I am getting the values and parse them with a JSON parser as explained here,
I can get all the values of the columns of my list without any issue, however I have a multi-choice column which returns the below string as the result of the Parse JSON action
{"__metadata":{"type":"Collection(Edm.String)"},"results":["Choice 2"]}
if I select two choices in my multi-choice column, I get the below result:
{"__metadata":{"type":"Collection(Edm.String)"},"results":["Choice 1","Choice 3"]}
How can I only get the value in the "results" section as a string such as "Choice 1","Choice 3" rather than the whole metadata string
Solución
Updating for [Send a HTTP..] request. Here [results] is an array, and [MyChoice] is also an array.
body('Parse_JSON')?['d']?['results'][1]['MyChoice'][0]['Value']
Here's how I can find individual choice value when retrieving list items using [Get items] -> [Parse JSON] -> [Apply to each]
Here for each item, [MyChoice] is the Property (column name of the multi-value), and [0] is the index of the first value. You can check the length of [MyChoice] and dynamically find each value.
items('Apply_to_each')['MyChoice'][0]['Value']
Updating the answer showing how to dynamically capture values from a multi-value column
Please see the screenshots and explanation below.
Please note that it's very important to analyze the output from [Send an HTTP..] by using a [Compose] action before feeding into [Parse JSON]