web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Power BI Query to Pars...
Power Automate
Suggested Answer

Power BI Query to Parse JSON to Dataverse giving apply to each error of string looking for array

(1) ShareShare
ReportReport
Posted on by 48
I've tried multiple ways and I can't get this flow to work right. Please help! 
 
My setup:
Trigger = weekly recurring
step 1 = run query against a dataset
step 2 = Parse JSON with exression 
body('Run_a_query_against_a_dataset')?['results']?[0]?['tables']?[0]?['rows']
step 3 = apply to each
body('Parse_JSON')
step 4 (in apply to each) = switch condition
step 5 = add a new row to selected environment
 
I continue to get this error on the apply to each: 
The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@{body('Parse_JSON')} ' is of type 'String'. The result must be a valid array.
Categories:
I have the same question (0)
  • Suggested answer
    Riyaz_riz11 Profile Picture
    3,893 Super User 2025 Season 2 on at
    Hi,
     

    Solution 1: Fix the Parse JSON Step

    Step A: Check the actual data structure


    1. Go to your flow run history

    2. Look at the output of "Run a query against a dataset"

    3. Expand the JSON to see the actual structure

    4. Check what ['results'][0]['tables'][0]['rows'] actually contains


    5.  

    Step B: Generate proper schema


    1. In Parse JSON step, click "Generate from sample"

    2. Use the actual output from your query step

    3. Paste the content of the rows array

    4. This will create the correct schema

    5.  

    Solution 2: Alternative Expression Approaches

    Option A: Use a different expression in Apply to each
    Instead of body('Parse_JSON'), try:

    outputs('Parse_JSON')

    Option B: Parse the string if it's JSON
    If the rows data is a JSON string, add a Compose action before Apply to each:

    json
    json(body('Parse_JSON'))

    Then use outputs('Compose') in Apply to each.

    Solution 3: Complete Rebuild (Recommended)

    Step 1: Initialize Variable


    • Add "Initialize variable" action after your query

    • Name: ParsedRows

    • Type: Array

    • Value:

    • body('Run_a_query_against_a_dataset')['results'][0]['tables'][0]['rows']

    Step 2: Skip Parse JSON


    • Remove the Parse JSON step entirely

    • Use the variable directly

    •  

    Step 3: Apply to Each


    • Input: variables('ParsedRows')

    Solution 4: Debugging Steps

    Add these temporary actions to debug:

    Debug Action 1: Compose - Check Query Output

    json
    body('Run_a_query_against_a_dataset')

    Debug Action 2: Compose - Check Rows Structure

     
    json
    body('Run_a_query_against_a_dataset')?['results']?[0]?['tables']?[0]?['rows']

    Debug Action 3: Compose - Check Type

     
    json
    string(body('Run_a_query_against_a_dataset')?['results']?[0]?['tables']?[0]?['rows'])

    Solution 5: Handle Different Data Types

    Add a condition before Apply to each:

    Condition: Check if it's an array

     
    json
    equals(string(type(body('Parse_JSON'))), 'Array')

    If True: Use body('Parse_JSON') in Apply to each
    If False: Use array(body('Parse_JSON')) or handle as string

    Recommended Fix (Step by Step)


    1. Remove Parse JSON step completely

    2. Add Initialize Variable after your query:

      • Name: TableRows

      • Type: Array

      • Value: body('Run_a_query_against_a_dataset')['results'][0]['tables'][0]['rows']

      •  

    3. Update Apply to each input to: variables('TableRows')

    4. In Switch condition, reference current item as: item()

    5. In Add new row, use: item()['ColumnName'] for specific values
     
    If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
    Regards,
    Riyaz

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard