Membrane API Gateway returns 500 Internal Server Error with the title Error parsing JSON when the json2Xml plugin cannot convert a JSON message into XML. The message is labeled as JSON, but its body cannot be parsed.
The response contains the status 500 Internal Server Error, the title Error parsing JSON, the message of the JSON parser, the problem type https://membrane-api.io/problems/internal/validation/json and a link to this page. The type means that the gateway failed while processing a JSON message. The flow field says whether the request or the response was affected, and in development mode the body field shows the first 200 characters of the body. In production mode, the title is replaced by Internal Server Error, the type is shortened to https://membrane-api.io/problems/internal, and the details are left out.
The status is 500 in both flows. If the request flow fails, the client sent the invalid body. If the response flow fails, the backend did.
The json2Xml plugin converts message bodies with a JSON Content-Type, such as application/json, into XML, for example to send a JSON request to an XML or SOAP backend. Messages without a JSON content type are passed on unchanged.
The body is declared as JSON but is truncated, contains a syntax error such as a trailing comma, or is not JSON at all. The message of the JSON parser in the response shows the position of the error.
The body cannot be read or decoded, for example because the Content-Encoding header is wrong or the sender aborted the transfer.
Content-Type for content that is not JSON.json2Xml, for example with OpenAPI validation or with a validator that uses a JSON schema.A validator in the request flow checks the JSON before the conversion runs:
api:
port: 2000
flow:
- request:
- validator:
jsonSchema: order.schema.json
# json2Xml goes here, after the validator
target:
url: https://api.predic8.de
api:
port: 2000
flow:
- request:
- validator:
jsonSchema: order.schema.json
# json2Xml goes here, after the validator
target:
url: https://api.predic8.de
By default, Membrane runs in development mode and adds details to error responses that help you find the problem. These details may reveal information about your setup. In production, turn them off:
configuration:
production: trueconfiguration: production: true
Add the configuration document to your apis.yaml and separate it from the APIs with ---. The title then reads Internal Server Error, and the details and the link to this page are left out. If the response contains a log key, search the gateway log for it to find the full error message.
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.