# XML to JSON is there a library script?

**URL:** <https://community.postman.com/t/xml-to-json-is-there-a-library-script/15077>\
**Category:** Help Hub\
**Tags:** json, xml-parsing\
**Created:** [August 17, 2020, 2:27pm UTC](https://community.postman.com/t/xml-to-json-is-there-a-library-script/15077 "2020-08-17T14:27:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cgreene](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@cgreene](https://community.postman.com/u/cgreene)\
**Post date:** [August 17, 2020, 2:27pm UTC](https://community.postman.com/t/xml-to-json-is-there-a-library-script/15077/1 "2020-08-17T14:27:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![odanylewycz](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/odanylewycz/32/3240_2.png) [@odanylewycz](https://community.postman.com/u/odanylewycz)\
**Post date:** [August 17, 2020, 3:55pm UTC](https://community.postman.com/t/xml-to-json-is-there-a-library-script/15077/2 "2020-08-17T15:55:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cgreene](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@cgreene](https://community.postman.com/u/cgreene)\
**Post date:** [August 17, 2020, 4:10pm UTC](https://community.postman.com/t/xml-to-json-is-there-a-library-script/15077/3 "2020-08-17T16:10:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![odanylewycz](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/odanylewycz/32/3240_2.png) [@odanylewycz](https://community.postman.com/u/odanylewycz)\
**Post date:** [August 17, 2020, 4:41pm UTC](https://community.postman.com/t/xml-to-json-is-there-a-library-script/15077/4 "2020-08-17T16:41:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jayaraman83](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jayaraman83](https://community.postman.com/u/jayaraman83)\
**Post date:** [June 7, 2024, 1:45am UTC](https://community.postman.com/t/xml-to-json-is-there-a-library-script/15077/6 "2024-06-07T01:45:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [June 7, 2024, 8:33am UTC](https://community.postman.com/t/xml-to-json-is-there-a-library-script/15077/7 "2024-06-07T08:33:14Z")

</div>

@jayaraman83

[Adding External Libraries in Postman | Postman Blog](https://blog.postman.com/adding-external-libraries-in-postman/)

[Using External Libraries | Postman Learning Center](https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-api-reference/#using-external-libraries)

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

[Occational warning that xml2Json is deptrecated - 🙋 Help - Postman Community](https://community.postman.com/t/occational-warning-that-xml2json-is-deptrecated/59745)
