Skip to main content

Fixed: "Invalid JSON. A Token Was Not Recognized in the JSON Content" from Send an HTTP Request to SharePoint

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

My flow failed with Invalid JSON. A token was not recognized in the JSON content. The JSON it sent looked fine in the designer. In the run, a false from my data had become False, with a capital F, which isn't JSON. An if() expression fixed it.

What I Was Doing​

The setup flow in Part 11 of the Career Development Plan series changes each list's settings with a Send an HTTP request to SharePoint action called Update the list settings (How to Change SharePoint List Settings with the REST API shows the action). Its body sets NoCrawl, which keeps a list out of search, from a noCrawl value in the flow's list definitions: false for one list, true for the other.

I put the value into the body with an expression, the same way I had put in the list's description:

Body (the part that failed)
"OnQuickLaunch": true,
"NoCrawl": @{items('For_each_list')?['noCrawl']}
}

NoCrawl takes a true-or-false value, so there are no quotes around the expression.

What I Expected​

"NoCrawl": false for the first list, and the settings saved.

What I Got​

The test run failed at Update the list settings, in the loop's first pass:

The failed run with the banner Flow run failed. Action 'Update_the_list_settings' failed with an odata.error, Microsoft.SharePoint.Client.InvalidClientQueryException and the message Invalid JSON. A token was, and For each list marked ActionFailed

The full error, with the request IDs masked:

Error
{
"odata.error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": {
"lang": "en-US",
"value": "Invalid JSON. A token was not recognized in the JSON content."
}
}
}

Create the list, just before it, had worked: the list existed on the site.

What I Checked​

  1. What the action actually sent. In the run, I selected Update the list settings and Show raw inputs. The end of the body read "NoCrawl": False:

    The raw inputs of Update the list settings, ending with "MajorVersionLimit": 50, and "NoCrawl": False followed by the closing brace

    JSON only has true and false, in lowercase. False is a word SharePoint doesn't recognize, which is exactly what the error says.

  2. Microsoft's Workflow Definition Language reference. An expression written as @{...} inside text is string interpolation, and the article says the result is always a string. Its example turns the number 42 into the text "42". My false was turned into text in the same way, and the text it became was False.

  3. The description. It used the same kind of expression and worked, because a description is text anyway, inside quotes.

Why It Happens​

The body box is text with expressions inside it. Each @{...} is replaced with text, and a true-or-false value comes out as True or False. That's fine inside a quoted string, but in place of a JSON true or false it breaks the JSON.

The Fix​

Write the text you need yourself, with if(). It returns its second value when the first is true, and its third when it's false (How to Use the if() Function):

Expression
if(items('For_each_list')?['noCrawl'], 'true', 'false')

In the body, it replaces the old expression:

Body (fixed)
"OnQuickLaunch": true,
"NoCrawl": @{if(items('For_each_list')?['noCrawl'], 'true', 'false')}
}

Now the text is true or false in lowercase, which is JSON.

After the Fix​

The body showed the new if(...) token:

The Update the list settings pane with the MERGE headers and the Body, where NoCrawl is set by an if(...) expression token

The next test run passed Update the list settings for both lists, and the list that should be hidden from search had NoCrawl turned on.

Common Mistakes​

MistakeWhat happensDo this instead
@{...} for a true-or-false value in a JSON bodyThe value is sent as True or FalseUse if(value, 'true', 'false')
Putting quotes around it to make it validThe value is sent as the text "False", not as a BooleanSend true or false without quotes
Reading only the designerThe body looks right thereCheck Show raw inputs in the run

Troubleshooting​

SymptomLikely causeFix
Invalid JSON. A token was not recognized in the JSON content.A value in the body isn't valid JSON, often True or FalseRead the raw inputs and fix that value
The same error with no expression involvedA typo in the body, such as a missing commaCheck the body's brackets, quotes and commas

FAQ​

Why didn't the designer warn me?​

The body is text with expressions in it, and the designer doesn't check whether the result will be valid JSON. You find out at run time.

Does a number have the same problem?​

No. A number becomes the same digits as text, and digits without quotes are valid JSON. Only True and False change.

Conclusion​

An expression inside text always becomes text, and a Boolean becomes True or False. In a JSON body, write the value with if(value, 'true', 'false'), and check a failed run's Show raw inputs to see what was really sent.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.