Convert OpenAPI YAML File to JSON

We can convert an OpenAPI (or Swagger) specification file into JSON using the yamljs utility.
We can install the binary globally command using:

$ npm install -g yamljs

This should make yaml2json available in the shell. We can then run:

$ yaml2json input.yaml -i4 -p > output.json

The output file is the JSON equivalent of the YAML spec.

The -p param means “pretty” and “-i4” means indentation of 4 spaces.

References

https://www.npmjs.com/package/yamljs

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *