Convert JSON to YAML Online

(and in every language)


Paste your JSON here


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.


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

# From stdin
cat example.json | json2yaml


import           Data.Aeson (decode)
import           System.Environment (getArgs)
import           Control.Monad (forM_)
import           Control.Applicative ((<$>))
import qualified Data.ByteString.Lazy.Char8 as BLC
import qualified Data.Yaml as Y

main :: IO ()
main = do
  args <- getArgs
  forM_ args $ \arg -> do  -- args is a list of JSON files
    j <- decode <$> BLC.readFile arg
    case j of 
      Nothing -> error "Invalid JSON file"
      Just v -> Y.encodeFile (arg ++ ".yaml") (v :: Y.Value)


(function () {
  "use strict";

  var YAML = require('json2yaml')
    , json
    , data
    , yml

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


JavaScript (browser only)

<script src=""></script>
(function () {
  "use strict";

  var YAML = window.YAML
    , json
    , data
    , yml

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



use JSON;
use YAML::XS;

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

print Dump decode_json $json;


import json
import yaml

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



require 'json'
require 'yaml'

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

puts yml


composer require symfony/yaml:2.*
require 'vendor/autoload.php';

use Symfony\Component\Yaml\Yaml;

$json = '{ "foo": "bar" }';
$data = json_decode($json, true);
$yml = Yaml::dump($data);

echo $yml;

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