Kafka Schema Registry getting error Unexpected character ('<' (code 60)) expected a valid value (number, String, array, object, 'true', 'false')
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
While working with Apache Kafka and its ecosystem, you might encounter various errors related to schema management when integrating Kafka Schema Registry. One such error is the "Unexpected character (< (code 60)): expected a valid value (number, String, array, object, 'true', 'false')." This article delves into the technical aspects of why this error occurs, provides examples, and offers solutions to resolve it.
Understanding the Error
The error "Unexpected character (< (code 60)): expected a valid value (number, String, array, object, 'true', 'false')" typically occurs when the Kafka Schema Registry client attempts to parse a response that it expects to be in JSON format, but instead, it encounters HTML or XML content starting with <. This usually indicates that the client is not communicating with the Schema Registry API as expected but might be interacting with a different service or hitting an incorrect URL.
Common Causes
- Incorrect URL: The most common cause of this issue is an error in the base URL used to access the Schema Registry. If the URL is incorrect, it might point to a different service that returns HTML or XML data, such as a web server's default page.
- Proxy or Load Balancer Configuration: If your Schema Registry is behind a proxy or a load balancer, misconfigurations can lead to routing problems where API calls are not directed to the Schema Registry but to other services that return HTML or XML.
- Network Issues: In some cases, redirect issues or network configurations in your environment might mistakenly direct requests to the wrong address.
- Server Misconfiguration: The Schema Registry server might be misconfigured, leading to unexpected responses. This is less common but worth checking if other causes have been ruled out.
How to Diagnose and Fix
Step 1: Verify the URL
Ensure that the URL configured in your client matches the actual URL where the Schema Registry is hosted. You can do this by using tools like curl:
The command should return a JSON response if the URL is correct.
Step 2: Check Proxy and Network Configuration
Verify that any proxy or network configuration such as DNS settings, routing rules, or load balancer settings correctly route the traffic intended for the Schema Registry.
Step 3: Server Health Check
Check the health and configuration of the Schema Registry server to ensure it is running and configured correctly. Consult the server logs for any indication of errors or misconfiguration.
Step 4: Content Type Validation
Ensure that the headers in responses from the Schema Registry contain Content-Type: application/json. If not, there might be a server-side issue that needs attention.
Example
An incorrect URL might look like this:
Correct URL should specify the API endpoint:
Summary Table
| Issue Component | Problem Indicator | Solution Step |
| URL | URL does not return JSON | Verify and correct the Schema Registry URL |
| Proxy/Network | Traffic not routed to Schema Registry | Check and adjust proxy or load balancer settings |
| Server Configuration | Unexpected server responses or failed health checks | Review and fix server settings and logs |
| Content Type | Non-JSON headers in response | Correct server settings to return proper headers |
Conclusion
Encountering an "Unexpected character" error when using Kafka Schema Registry usually points towards a misdirection issue where the client does not communicate with the intended server. By carefully checking the configurations, URLs, and server settings, you can resolve this issue effectively and ensure smooth operation of your data streaming architecture. Remember to always verify your environment after making configuration changes to ensure everything operates as expected.

