tj / js-yaml

CommonJS YAML Parser -- fast, elegant and tiny yaml parser for javascript
276 stars 41 forks source link

JSON/Object to YAML? #40

Open ghost opened 12 years ago

ghost commented 12 years ago

Is it possible to convert a JSON or Javascript object into YAML?

coolaj86 commented 12 years ago

I just wrote a stringifier and a cli for both the parser and the stringifier.

npm install -g json2yaml yaml2json

Example:

(function () {
  "use strict";

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

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

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