Skip to content
Latchkey

REST Assured Jackson "JsonParseException" on the response body in CI

REST Assured used Jackson to deserialize the response body as JSON, but the body was not valid JSON. In CI this is usually an HTML error page, an empty body, or a proxy interstitial returned instead of the expected JSON.

What this error means

A test fails with "com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60))" when calling .as(), jsonPath(), or a JSON body matcher.

REST Assured
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)):
expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"<!DOCTYPE html>..."; line: 1, column: 2]

Common causes

The response was HTML, not JSON

A 500 error page, a login redirect, or a gateway page returns HTML, so parsing the body as JSON fails on the first "<".

An empty or truncated body

A 204 No Content or a dropped connection returns nothing to parse, and Jackson raises a parse error.

How to fix it

Assert content type and log the body first

  1. Assert the response Content-Type is application/json before parsing.
  2. Log the body on failure to see what was actually returned.
  3. Fix the upstream cause (auth, error page) so real JSON comes back.
Java
given().accept("application/json")
  .when().get("/users/1")
  .then().contentType("application/json").log().ifValidationFails();

Handle the error response explicitly

If an endpoint can return HTML on error, assert the status first so you fail on the status, not on a confusing parse error.

How to prevent it

  • Assert Content-Type before deserializing the body.
  • Check status before parsing so error pages fail clearly.
  • Ensure auth is configured so you do not receive login HTML.

Frequently asked questions

What causes ""JsonParseException: Unexpected character""?
A 500 error page, a login redirect, or a gateway page returns HTML, so parsing the body as JSON fails on the first "<".
How do I fix "JsonParseException: Unexpected character"?
Assert content type and log the body first

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card