3

I'm trying to fetch an item from a list to perform some operations on (parsing JSON specifically) but when I use the Get Items action it returns an array, even if I select the top 1 from the results. The Parse JSON action can't take an array as input, only a single object. What can I do to prepare the item(s) in the Get Items action to be parsed?

Edit: Here's a screen cap of a simple workflow where I'm trying out this operation. When I try to Compose the People field from the Get Items action, it embeds it in a loop to go through the whole array of people. The problem is that I need to select one of those people and then make them available for the Parse JSON action to work its magic and let me access their DisplayName. sample image

Also when trying to Parse a single instance of the People column, I get this error: "Invalid type. Expected Object but got Array."

3 Answers 3

2

Here are the steps that I would follow:

  1. After [Get Items] action add a [Compose] action
  2. Execute the Flow and examine the output from the [Compose].
  3. Copy the output of the [Compose] into clipboard
  4. Add [Parse JSON] action and use the output from step 3 as sample data to generate schema
  5. Add addition actions like another [Compose] action to verify the Parse Data. Properties should be available from the Dynamic content.

To get a particular item's property, you can use the expression shown below. Here [0] indicates the first item in the [Parse JSON] output, which is an array, and ['LastName'] is a list column (property).

body('Parse_JSON')?[0]['LastName']

enter image description here

Here is an article describing how to work with JSON in Flow

4
  • 1
    I must be missing something here, every time I try to parse the output from the first compose action it throws the same error about being unable to parse an array.
    – thanby
    Dec 2, 2020 at 14:12
  • What error messages are you getting? Is it something Null reference? If a property is defined as required in the JSON schema and Null values are returned by [Get Items], Parse JSON may fail. Please refer to Article showing how to correct the schema for Null values. Or Just test it with a simple one-two-column list first and then work with more complex list Dec 2, 2020 at 15:00
  • The first issue is with the first Compose action. When I put the People field into its inputs, it embeds it in a loop because People gets returned as an array. When it's in that loop I can't access the People outside it. And even when I can, they're still in an array that Parse JSON won't handle. See my edit above.
    – thanby
    Dec 2, 2020 at 16:43
  • See the screenshot that I've posted in my response - Add the [Value] or [Body] from the output of [Get Items] to the [Compose] action. Depending on what your are trying to do, [People] type can work as Input to [Compose]. Dec 2, 2020 at 17:57
2

First of all, I wanted to suggest the action Get Item instead of Get Items if you only want one specific item, and you have the item ID.

The Get Items action will result in a loop even if you only have one item to retrieve from it.

If Get Item can't be an option, I'd suggest saving the item in an Object variable and working with that variable instead of the item property.

4
  • There is no "Get Item" in Power Automate that I'm aware of, only "Get Items"
    – thanby
    Dec 2, 2020 at 18:24
  • 1
    There actually is, I use it a lot because it avoids the "Get Items" loop. printscreen
    – puppycat
    Dec 2, 2020 at 18:43
  • We must have it disabled or something because it's just not showing up in my list of actions ibb.co/RC7VMHN
    – thanby
    Dec 2, 2020 at 19:51
  • 1
    I usually search the actions so I haven't noticed this, but it's not close to the "Get Items" action. Please search near the end, above "Get list views" image
    – puppycat
    Dec 2, 2020 at 19:56
0
  1. Set Value to 1 for Top Count in Get Items

Get Items > Top Count > 1

  1. Go to settings Turn on pagination and set value 1 to Threshold field.

Settings > On Pagination > Value 1 for Threshold

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.