Getting an error message when query Cosmos, parse json and then iterate through the result so i can set the result of a field in a parameter that I can use

Brian Hood 21 Reputation points
2022-06-06T00:00:21.163+00:00

I am getting the following error in my logic app. The overall structure of the logic app is shown in the attached (#1). The "query cosmos document" step returns 1 document and that output is shown in the attached (#2). Then, I parse JSON and the raw output is shown in the attached #3. Everything looks good until I do my for next loop to set my variable so that I can use the variable later on in the logic app. #4 in the attached shows the schema that I used to define my parse json routine in #3. The Last step (for each 5) in the attached #5 is where I get my error. #5 shows the parameter I am using in the for next loop, and then the error message under it (see below). Do you have any ideas on what I could do to resolve the error?

ExpressionEvaluationFailed. The execution of template action 'For_each_4' failed: the result of the evaluation of 'foreach' expression '@Tomas Podoba ('Parse_JSON_2')?['items']' is of type 'Null'. The result must be a valid array.

Thanks
208582-logic-app-error.pdf

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2022-06-09T04:27:56.453+00:00

    @Brian Hood Thanks for sharing more details. As you have mentioned that you are only retrieving one document so the array will always have one element so you need to have JSON schema without array and in the Content you should only specify the first element of the array.
    You can leverage the Parse JSON that will create user-friendly fields or tokens. Now you can leverage these fields/token in the next action of your workflow.

    You need to update the content with outputs('yourtriggername')[0] as I can see the trigger name as "Query documents v5 2" in your pdf screenshot so it should be outputs('Query_documents_v5_2')[0] but please validate the same at your end. For more details on outputs function please refer to this document.

    209741-image.png

    Parse JSON Schema:

    {  
        "properties": {  
            " RoomPresenseStatus ": {  
                "type": "string"  
            },  
            "Room": {  
                "type": "string"  
            },  
            "id": {  
                "type": "string"  
            }  
        },  
        "type": "object"  
    }  
    

    You can see the Parse JSON output has created user-friendly fields that you can leverage in your next action.
    209732-image.png

    Update:
    Thanks for your time over the call. As discussed, we have leveraged the expression below in our Parse Json schema in your workflow along with the above schema.
    Walkthrough how you can test and troubleshoot any failed run in your workflow.

    body('Query_documents_v5_2')?['value'][0]  
    

    Feel free to get back to me if you need any assistance.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.