XML to JSON is there a library script?

Hi,
When using Quick Base APIs, Quick base delivers the payload in XML format. How can I import the library script, or find the library script that will convert that XML to JSON?

Specifically, I use the API_DoQuery in the query string of the URL along with validation token, parameters, etc.

The payload will always by default come back as XML. Can Postman provide a way to convert that to JSON notation?

Thank you,
cgreene

2 Likes

Hi @cgreene,

Going off your other post, you can use xml2js. Something as simple as below should work:

 const xml2js = require('xml2js');   
 xml2js.parseString(pm.response.text(), function (err, result) {
        console.log(result);
    });

That should spit out json for you.

Best,
Orest

1 Like

Hi odanylewycz
Thank you for your reply and code snippet. I pasted that in the TESTS window and clicked SEND. Wondering if I’m using the code correctly as there was a problem.
Thank you again for you help. From this point I will immerse myself in study of Postman and learn this platform.
ReferenceError: xml2js is not defined
cgreene

Hi @cgreene,

You’re welcome!

I didnt explain well enough in my prior response on how to use the library, my apologies. I was under the impression that the libraries were imported by default, maybe they were at some point but now you have to explicitly import them via require.

I have updated the example above, and that should work as I just tested it successfully.

Hope this helps!

Orest

Hi Orest,
Thanks for your code snippet and even i got the same error that Cannot find module ‘xml2js’ and how do we import via require explicitly ? can you paste the code snippet for that as well ?
Regards,
Jay

@jayaraman83

Adding External Libraries in Postman | Postman Blog

Using External Libraries | Postman Learning Center

Here is a topic that includes some examples and a conversation that might be of use.

Occational warning that xml2Json is deptrecated - :person_raising_hand: Help - Postman Community