apache/seatunnel · error · IllegalArgumentException
Invalid JSON format in request body.
Error message
Invalid JSON format in request body.
What it means
requestHandle converts the raw request bytes to JSON via RestUtil.convertByteToJsonNode. If the bytes are present but not valid JSON (IOException), it throws IllegalArgumentException("Invalid JSON format in request body.").
Source
Thrown at seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/BaseService.java:1257
}
} else {
strValue = value.toString();
}
members.add(key, strValue);
}
});
return members;
}
protected JsonNode requestHandle(byte[] requestBody) {
if (requestBody.length == 0) {
throw new IllegalArgumentException("Request body is empty.");
}
JsonNode requestBodyJsonNode;
try {
requestBodyJsonNode = RestUtil.convertByteToJsonNode(requestBody);
} catch (IOException e) {
throw new IllegalArgumentException("Invalid JSON format in request body.");
}
return requestBodyJsonNode;
}
protected void handleStopJob(
Map<String, Object> map, SeaTunnelServer seaTunnelServer, Node node) {
boolean isStopWithSavePoint = false;
if (map.get(RestConstant.JOB_ID) == null) {
throw new IllegalArgumentException("jobId cannot be empty.");
}
long jobId = Long.parseLong(map.get(RestConstant.JOB_ID).toString());
if (map.get(RestConstant.IS_STOP_WITH_SAVE_POINT) != null) {
isStopWithSavePoint =
Boolean.parseBoolean(map.get(RestConstant.IS_STOP_WITH_SAVE_POINT).toString());
}
boolean forceStop = false;
if (map.get(RestConstant.FORCE) != null) {
forceStop = Boolean.parseBoolean(map.get(RestConstant.FORCE).toString());View on GitHub (pinned to cf67b549a7)
Solutions
- Validate the JSON payload with a JSON parser before sending
- Quote the body correctly in shell (use single quotes or heredoc) to avoid shell mangling
- Send proper Content-Type: application/json and a JSON-serializable body
Example fix
// before
curl -d '{"jobId": 123,' ... // malformed JSON
// after
curl -H 'Content-Type: application/json' -d '{"jobId":"123"}' ... Defensive patterns
Strategy: validation
Validate before calling
JSON.parse(payload); // throws early if invalid before HTTP call
Try / catch
try {
const res = await post(url, JSON.stringify(payload));
} catch (e) {
if (String(e).includes('Invalid JSON format')) {
// fix serialization/quoting and resend
}
} Prevention
- Validate JSON before sending (linters/parsers)
- Quote bodies correctly in shell commands
- Never send form-encoded or YAML bodies to JSON endpoints
When it happens
Trigger: POSTing malformed JSON (missing braces/quotes, trailing commas) or a non-JSON payload (plain text, form-encoded) to body-based REST endpoints.
Common situations: Hand-written curl payloads with quoting mistakes on the shell; wrong Content-Type causing garbled encoding; clients sending YAML/XML instead of JSON.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- AmazonDocumentDB option '' must be a valid BSON/JSON documen
- Unexpected JSON payload format from Firebase
- Invalid sort JSON:
- Request body is empty.
- jobId cannot be empty.
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/b6639a3f3d9278a9.
Report an issue: GitHub.