Error Reference

JSON parse error: response body is not valid JSON

JSON parse error: response body is not valid JSON

Where this appears

This error appears in ServiceNow application logs and REST message logs when an outbound REST call expects a JSON response but receives HTML, XML, or malformed content instead. The error typically occurs during REST API integrations, business rule executions, or scheduled import operations that make external web service calls.

Sourdough
Chrome Extension

Debugging this in a real instance?

Sourdough lets you trace "JSON parse error: response body is not valid JSON" through system logs, script errors, and API health in the ServiceNow tab you are already using.

Add to Chrome

Free to install. Pro $5/month after a 14-day no-card trial.
Pro requires the ServiceNow admin role. Upgrade inside the extension.

Overview
Tasks
CMDB
API
Metrics
Monitor
Internals
Instance:sourdoughdev·Version:Yokohama
Instance StateONLINE
System StatusFully Operational
Session Timeout90 minutes
Logged-In Sessions2 (20 active)
Build Nameyokohama-12-18-2024_p1
IP Address10.159.128.43
Instance HealthHealth Score: 90%
🔥 5dSourdough (Chrome Plugin)Dark Mode

Cause

The external endpoint returned an HTML error page (404, 500, authentication page) instead of JSON due to incorrect URL, authentication failure, or server error. (high likelihood)

The REST call timed out and received a partial response or proxy error page from network infrastructure or load balancers. (high likelihood)

The external API returned XML or plain text content when the REST message was configured to expect JSON response format. (medium likelihood)

Authentication credentials are invalid or expired, causing the external service to return an HTML login page or error page instead of API data. (medium likelihood)

The external endpoint URL has changed or the API version is deprecated, resulting in redirect pages or error messages in HTML format. (low likelihood)

Fix

Step 1: Navigate to System Web Services > Outbound > REST Message Logs to locate the failed REST call and examine the actual response body content.

Step 2: Check the HTTP status code in the REST message log - if it's 404, 401, 403, or 5xx, the endpoint URL or authentication needs correction before addressing JSON parsing.

Step 3: Verify the endpoint URL is correct by testing it directly in a browser or REST client tool like Postman to confirm it returns valid JSON.

Step 4: Review authentication settings in the REST message by checking HTTP headers, basic auth credentials, or OAuth configuration under the Authentication tab.

Step 5: Increase the timeout value in the REST message configuration if the response indicates timeout or partial content issues.

Step 6: Modify the REST message to handle non-JSON responses by checking the Content-Type header first or using try-catch logic in business rules before parsing JSON.

Step 7: Add error handling in your business rule or script to validate response format using responseBody.startsWith('{') before calling JSON.parse() or response.getBody().

Step 8: Test the corrected REST message using the Test functionality in the REST Message record to verify JSON parsing works before deploying to production.

Test Your Knowledge

Quick 3-question quiz. See how your ServiceNow skills stack up.

Question 1 of 3Performance

A list view on a table with millions of records is slow. Best fix?

Select an answer to continue