# Convert yaml to json in script

**URL:** <https://community.postman.com/t/convert-yaml-to-json-in-script/4309>\
**Category:** Help Hub\
**Created:** [February 28, 2019, 3:34pm UTC](https://community.postman.com/t/convert-yaml-to-json-in-script/4309 "2019-02-28T15:34:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![houbie](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@houbie](https://community.postman.com/u/houbie)\
**Post date:** [February 28, 2019, 3:34pm UTC](https://community.postman.com/t/convert-yaml-to-json-in-script/4309/1 "2019-02-28T15:34:45Z")

</div>

Postman lists both [js-yaml](https://github.com/nodeca/js-yaml) and [yaml.js](https://github.com/jeremyfa/yaml.js) as dependencies.  
Is one of them exposed in the scripts?  
I would like to convert my openApi yaml to json so that I can validate API responses against their schema’s inside the API spec (the yaml would be fetched from github)

---

<div class="post-metadata">

**Author:** ![Gregoire\_Thibaud](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@Gregoire\_Thibaud](https://community.postman.com/u/Gregoire_Thibaud)\
**Post date:** [January 27, 2020, 1:46pm UTC](https://community.postman.com/t/convert-yaml-to-json-in-script/4309/2 "2020-01-27T13:46:35Z")

</div>

Hello @houbie,

I worked on the same issue and I found a solution. I stored the source code of yaml-js into a global variable using its CDN ([https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.13.1/js-yaml.js](https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.13.1/js-yaml.js)) and then I imported it into my request scripts (see the code below):

```
// Import yaml-js library (stored in global variable)
const yaml = pm.globals.get('yaml-js');
(new Function(yaml))();
// Convert API specifications to JSON (initially in YAML format)
let specs = jsyaml.load(pm.response.text());

```

Hope it will help!

Best,

Grégoire
