1. Home
  2. ...
  3. FAQs
  4. How to convert the body of a TXT or XML request to JSON?

How to convert the body of a TXT or XML request to JSON?

Native transformation interceptors and the Custom JavaScript alternative.

You can use native transformation interceptors to do this. With them, it's possible to convert both the request and response body from XML or TXT to JSON and vice versa.

Access your API or Plan and click on Edit;

In the Flows section, select the Transformation tab;

Click on the interceptor you want (XML to JSON and/or TXT to JSON) and drag it to the flow.

A window will open with the interceptor's notes. Click on Save;

Click on Continue and Save to keep the changes.

Alternatively, you can also create a Custom JavaScript interceptor for this function. Go to API Design > Interceptors and follow the steps:

In the Custom Interceptors section, access your Custom JavaScript or create a new one;

In the editor, enter the script:

Click on Save to keep the change.

See the gif below with these steps:

How happy are you with this page?

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more