1
0
Fork 0
A command-line utility to convert a JSON file (.json) to YAML (.yml)
Datei suchen
AJ ONeal be09bf9dd3 v1.2.0 support dates 2018-09-22 13:55:59 -06:00
tests added json2yaml 2012-01-30 13:18:18 -07:00
.gitignore ignore node_modules 2013-07-29 00:39:43 -07:00
LICENSE added LICENSE and other meta stuff 2013-07-27 20:51:29 -07:00
README.md fix #21 note official location 2018-09-22 13:52:20 -06:00
cli.js Multiline 2016-04-28 14:50:01 +01:00
example.json added case of empty object and empty array 2013-07-28 23:09:20 -07:00
example.yml added json2yaml 2012-01-30 13:18:18 -07:00
index.js Multiline 2016-04-28 14:50:01 +01:00
package.json v1.2.0 support dates 2018-09-22 13:55:59 -06:00
test.sh added json2yaml 2012-01-30 13:18:18 -07:00

README.md

Unmaintained Mirror

Please go to the real repo at https://git.coolaj86.com/coolaj86/json2yaml.js

json2yaml

A command-line utility to convert JSON to YAML (meaning a .json file to a .yml file)

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).

Installation

npm install -g json2yaml

Note: To use npm and json2yaml you must have installed NodeJS.

Usage

Specify a file:

json2yaml ./example.json > ./example.yml

yaml2json ./example.yml | json2yaml > ./example.yml

Or pipe from stdin:

curl -s http://foobar3000.com/echo/echo.json | json2yaml

wget -qO- http://foobar3000.com/echo/echo.json | json2yaml

Or require:

(function () {
  "use strict";

  var YAML = require('json2yaml')
    , ymlText
    ;

    ymlText = YAML.stringify({
      "foo": "bar"
    , "baz": "corge"
    });

    console.log(ymlText);
}());

Example

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"
}

becomes

---
  foo: "bar"
  baz:
    - "qux"
    - "quxx"
  corge: null
  grault: 1
  garply: true
  waldo: "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.

Alias

json2yaml has the following aliases:

  • jsontoyaml
  • json2yml
  • jsontoyml