JSON_PARSER_ERROR" salesforce rest api
Fixes Salesforce REST JSON_PARSER_ERROR: the request body is not valid JSON. Validate the payload, check quoting and trailing commas, and confirm the Content-Type header. Use when REST calls fail with this error. Not for XML or form-encoded issues.
TL;DR
The JSON body is malformed: a trailing comma, single quotes, unescaped characters, or a truncated payload. Validate the exact bytes you sent with a JSON parser, fix the syntax, and resend. The API never parses partial JSON; the whole body must be valid.
Error
[ {
"message" : "Unexpected character ('}' (code 125)): was expecting double-quote to start field name",
"errorCode" : "JSON_PARSER_ERROR"
} ]Steps
- Log the exact request body bytes your client sent, not the object you think you sent. Expected: you see the real payload including any truncation.
- Run it through a JSON validator (python -m json.tool on the logged bytes). Expected: the validator points at the exact character.
- Fix the syntax: remove trailing commas, use double quotes, escape control characters in string values. Expected: the payload validates cleanly.
- Confirm the Content-Type header is application/json. Expected: the API parses the body as JSON instead of rejecting it.
- If the payload is built by string concatenation, switch to a real JSON serializer. Expected: malformed bodies stop occurring.
When to use
- REST calls fail with JSONPARSERERROR.
- An agent builds JSON by hand and intermittent calls fail (interpolation bugs).
- After adding a new field with special characters to the payload.
When not to use
- XML API errors (different parser).
- 400s with valid JSON (then the data is wrong, not the syntax).
Tool compatibility
- Salesforce REST API; any HTTP client.
- JSON serializers in Python, Node, and Java.
Variant phrasings
Unexpected character in JSON
The parser names the offending character; look just before it.
was expecting double-quote to start field name
Usually a trailing comma or single quotes.
Why it happens
Hand-built JSON breaks on edge data URIs quotes inside names, newlines in text fields, and unicode that was not escaped. Serializers handle all of this; string templates do not.
Edge cases
- Truncated bodies from timeouts parse as unexpected end of input; check content length.
- Emoji and unicode need proper UTF-8; mis-encoded bytes fail the parser.
- Composite API subrequests each need valid JSON; one bad subrequest fails the batch.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_NAqID4yCojficJaTQRoqpw
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.