-
Notifications
You must be signed in to change notification settings - Fork 855
Support parsing YAML in postman tests #12557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As a potential short term solution you could bring in the lib through a CDN and store the function as a Global variable. Add this to the Pre-request script (At the level that makes sense to you): if (!pm.globals.has('jsyaml_lib')) {
pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js", (err, res) => {
pm.globals.set("jsyaml_lib", res.text());
})
} I've used As a usage example, you can use the libs functions in your tests like this: // Import yaml-js library (stored in global variable)
const yaml = pm.globals.get('jsyaml_lib');
(new Function(yaml))();
let yamlFile = `
- martin:
name: Martin D'vloper
job: Developer
skills:
- python
- perl
- pascal
- tabitha:
name: Tabitha Bitumen
job: Developer
skills:
- lisp
- fortran
- erlang
`
// Convert data to JSON which was initially in YAML format
let specs = jsyaml.load(yamlFile);
console.log(specs); I've just mocked out a That will output something like this: |
@DannyDainton Thanks. That is a helpful workaround and general pattern. However, I still believe that this should be integrated directly into Postman since working with YAML data is very common nowadays, and being able to at least convert between the types would be incredibly useful. That being said, this is a very useful workaround for the time being. |
Is there an existing request for this feature?
Is your feature request related to a problem?
I am making an API calls that returns YAML and I need to be able to parse the YAML, either directly or by converting it into JSON.
Describe the solution you'd like
Ideally, I want to be able to do something like this:
const creds = YAML.parse(kubeconfig)
but even having access to js-yaml would be very useful.
Describe alternatives you've considered
Treating the YAML like a big string and just trying to cut stuff out of it.
Additional context
YAML is used a ton in Kubernetes and other modern platforms, and being able to parse it is important in various circumstances.
The text was updated successfully, but these errors were encountered: