Invalid JSON format – Action expected a different data format (JSON parsing issue).

Loading

Power Automate often interacts with external services, APIs, and data sources that exchange information using JSON (JavaScript Object Notation). If an action expects data in JSON format but receives incorrect formatting, the flow may fail with the following error:

“Invalid JSON format – Action expected a different data format (JSON parsing issue).”

This error occurs when Power Automate cannot parse or process the JSON due to syntax errors, missing fields, or incorrect data types.


2. Causes of “Invalid JSON Format” Error

Several issues can lead to this error:

  1. Incorrect JSON Syntax – Missing brackets, quotes, commas, or colons.
  2. Unexpected Data Types – Numbers, strings, or boolean values not formatted correctly.
  3. Missing or Extra Fields – The JSON structure does not match what the action expects.
  4. Escaping Issues – Special characters (e.g., double quotes inside a string) not properly escaped.
  5. Empty or Null JSON – The action receives {} or null instead of a properly structured JSON object.
  6. Encoding Issues – The JSON data is in an incompatible encoding (e.g., UTF-16 instead of UTF-8).
  7. API Response Issues – An API returns an error message instead of expected JSON data.
  8. Dynamic Content Not Resolving Properly – A variable or dynamic expression results in an invalid JSON structure.

3. Step-by-Step Troubleshooting Guide

Step 1: Identify the Failing Action

  1. Open Power Automate (https://flow.microsoft.com).
  2. Navigate to My Flows and select the affected flow.
  3. Click Run History and locate the failed run.
  4. Expand the failed action and look at the error message in the Inputs and Outputs sections.

Solution:

  • Copy the JSON from the Inputs section and validate it using a JSON validator (https://jsonlint.com).

Step 2: Check for JSON Syntax Errors

JSON must follow specific formatting rules:
Correct Example:

{
"name": "John Doe",
"age": 30,
"email": "john@example.com"
}

Incorrect Example (missing quotes around keys):

{ name: John Doe, age: 30, email: "john@example.com" }

Solution:

  • Ensure all keys and string values are enclosed in double quotes (").
  • Check that colons (:) separate keys from values and commas (,) separate key-value pairs.

Example Fix:

  • { name: John Doe, age: 30, email: "john@example.com" }
  • { "name": "John Doe", "age": 30, "email": "john@example.com" }

Step 3: Ensure Data Types Are Correct

JSON expects specific data types:
Correct Example:

{
"price": 25.99,
"available": true,
"quantity": 5
}

Incorrect Example (improper data types):

{
"price": "25.99",
"available": "true",
"quantity": "five"
}

Solution:

  • Numbers should not have quotes (25.99, not "25.99").
  • Boolean values should be true or false, not "true" or "false".

Step 4: Validate JSON Before Sending to Actions

Use the “Parse JSON” action to validate JSON before processing it.

Solution:

  1. Add a “Parse JSON” action before the failing action.
  2. In the Content field, use the dynamic content where the JSON data comes from.
  3. Click Generate from Sample, then paste a valid JSON sample.
  4. Run the flow again.

Example:

  • If an HTTP request returns JSON, use “Parse JSON” before accessing its fields.

Step 5: Check for Escaping Issues

If JSON contains special characters (e.g., double quotes inside a string), they must be escaped properly.

Correct Example:

{
"message": "Hello, \"John\"!"
}

Incorrect Example (unescaped quotes):

{
"message": "Hello, "John"!"
}

Solution:

  • Use a backslash (\) before special characters inside a string.
  • Alternatively, use single quotes (') instead of double quotes within the string.

Example Fix:

  • { "message": "Hello, "John"!" }
  • { "message": "Hello, \"John\"!" }

Step 6: Check for Missing or Extra Fields

Some APIs require a specific JSON structure. If a field is missing or unexpected, the action may fail.

Solution:

  • Verify the expected JSON schema from the API documentation.
  • If using Parse JSON, ensure the schema matches the API response.

Example:

  • If an API expects "user_id" but receives "id", it may fail.

Step 7: Handle Null or Empty JSON Responses

Some services return null or {} when no data is available.

Solution:

  1. Add a Condition to check if the JSON response is empty: if(empty(outputs('HTTP_Request')), 'No Data Available', outputs('HTTP_Request'))
  2. Use Coalesce to provide a default value: plaintextCopyEditcoalesce(outputs('HTTP_Request'), '{}')

Example:

  • If calling an API that sometimes returns {}, ensure your flow handles empty responses properly.

Step 8: Verify API Response Encoding

Some APIs return JSON in formats like UTF-16 instead of UTF-8, causing Power Automate to misinterpret the response.

Solution:

  • Check the Content-Type of the API response (should be application/json; charset=UTF-8).
  • Convert encoding using Power Automate expressions if necessary.

Example:

  • If an API returns JSON with Content-Type: text/plain, Power Automate may not parse it correctly.

4. Preventative Measures

To avoid “Invalid JSON Format” errors in the future:

Always validate JSON before using it in a flow (https://jsonlint.com).
Use the “Parse JSON” action to enforce correct data structures.
Check API documentation for expected JSON formats.
Escape special characters inside JSON strings.
Use conditions to handle null or empty JSON responses.
Ensure all keys and values follow correct JSON syntax.
Monitor API responses for unexpected changes.

Leave a Reply

Your email address will not be published. Required fields are marked *