A commandline utility to convert JSON to YAML / YML
A command-line utility to convert JSON to YAML (meaning a
.json file to a
The purpose of this utility is to pretty-print JSON in the human-readable YAML object notation (ignore the misnomer, YAML is not a Markup Language at all).
npm install -g json2yaml
Note: To use
json2yaml you must have installed NodeJS.
Specify a file:
json2yaml ./example.json > ./example.ymlyaml2json ./example.yml | json2yaml > ./example.yml
Or pipe from stdin:
curl -s | json2yamlwget -qO- | json2yaml
"use strict";var YAML = require'json2yaml'ymlText;ymlText = YAMLstringify"foo": "bar""baz": "corge";console.logymlText;;
So, for all the times you want to turn JSON int YAML (YML):
"foo": "bar""baz":"qux""quxx""corge": null"grault": 1"garply": true"waldo": "false""fred": "undefined"
---foo: "bar"baz:- "qux"- "quxx"corge: nullgrault: 1garply: truewaldo: "false"fred: "undefined"
Note: In fact, both of those Object Notations qualify as YAML because JSON technically is a proper subset of YAML. That is to say that all proper YAML parsers parse proper JSON.
YAML can use either whitespace and dashes or brackets and commas.
For human readability, the whitespace-based YAML is preferrable. For compression and computer readability, the JSON syntax of YAML is preferrable.
json2yaml has the following aliases: