Ask a Question

Working with XML APIs and Converting Response to JSON

SOLVED
nolandsmith
New Contributor

Working with XML APIs and Converting Response to JSON

Hello - I'm a bit new to this, but I am working with an XML API. 

 

Even when I set the "Response content type" to application/json, the response is still in XML. Is there a way I can ensure I will return JSON every time?

 

nolandsmith_0-1663238710708.png

 

3 REPLIES 3
chichepo
Contributor

Hello @nolandsmith
I am not sure why you can't get it.
Can you send your object description?

You can check this example:


1 - You declare your media types

chichepo_0-1663241595983.pngchichepo_2-1663241835614.png

 

 

2 - Then you check your object declaration

chichepo_1-1663241689239.png

I took the petstore file example

I hope it can help 😏



Thanks for the support! 

 

I don't even have application/xml as an applicable response content, yet it is still returning XML.

 

I do know that the API is an XML api (abr.business.gov.au/abrxmlsearch/abrxmlsearch.asmx/SearchByABNv202001). Could this be the reason I am only getting XML, or is there a way for Swagger to be able to return it as JSON?

 

nolandsmith_0-1663321345506.pngnolandsmith_1-1663321392636.png

nolandsmith_2-1663321727246.png

 

 

 

@nolandsmith 

I did some digging into your file and I did manage to generate a JSON response but ONLY as an example!!
Look at the file in attachement.

The sole response content type provided by the server is:

Content-Type: text/xml; charset=utf-8

and, I guess, this is the reason why it can't be displayed in JSON (message ref here)

 
Let us know if you find a solution

cancel
Showing results for 
Search instead for 
Did you mean: