Convert JSON to YAML Online

(and in every language)

JSON

Paste your JSON here

YML

See the YML output here


Converting JSON to YAML is a two part process.

First you have to convert a string of JSON into an object in whichever language you're using. This process is referred to as to parse or to deserialize.

Next you'll need to convert that object into a YAML string. This process is referred to as to emit, to serialize, or to stringify.

Technically speaking, JSON already is YAML since YAML allows for the use of brackets and commas in the exact same way that JSON does. However, for the sake of human-readability, it's very convenient to use the whitespace syntax of YAML without any brackets.

Bash

npm install -g json2yaml
# From file
json2yaml example.json

# From stdin
cat example.json | json2yaml

JavaScript

(function () {
  "use strict";
  
  var YAML = require('json2yaml')
    , json
    , data
    , yml
    ;
    
  json = '{ "foo": "bar" }';
  data = JSON.parse(json);
  yml = YAML.stringify(data);
  
  console.log(yml);
}());

JavaScript (browser only)

<script src="http://jsontoyaml.com/js/json2yaml.js"></script>
(function () {
  "use strict";
  
  var YAML = window.YAML
    , json
    , data
    , yml
    ;
    
  json = '{ "foo": "bar" }';
  data = JSON.parse(json);
  yml = YAML.stringify(data);
  
  console.log(yml);
}());

Ruby

require 'json'
require 'yaml'

json = '{ "foo": "bar" }'
data = JSON.parse(json)
yml = YAML::dump(data)

puts yml

Python

import json
import yaml

str = '{ "foo": "bar" }'
data = json.loads(str)
yml = yaml.safe_dump(data)

print(yml)

Perl

use JSON;
use YAML::XS;

my $json = <<'...';
{
  "foo": "bar"
}
...

print Dump decode_json $json;

Other languages...

Want to see to to convert JSON to YAML in your favorite language?

Please request an example or add it yourself (you can use examples/ruby.jade as a template).