-
-
Save sportebois/528dd2fd5373900b16a07f23e7fe6d24 to your computer and use it in GitHub Desktop.
load-yaml-dump-json A script to test YAML load against many implementations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: | |
# | |
# cat file.yml | load-yaml-dump-json | |
# ./load-yaml-dump-json # enter data and ctl-d when finished | |
yaml=`cat` | |
echo == Perl | |
echo YAML.pm: | |
echo "$yaml" | perl -0E 'use YAML; use JSON; say encode_json Load <>' | |
echo YAML::XS: | |
echo "$yaml" | perl -0E 'use YAML::XS; use JSON; say encode_json Load <>' | |
echo YAML::Syck: | |
echo "$yaml" | perl -0E 'use YAML::Syck; use JSON; say encode_json Load <>' | |
echo YAML::Tiny: | |
echo "$yaml" | perl -0E 'use YAML::Tiny; use JSON; say encode_json Load <>' | |
echo | |
echo == Python== | |
echo PyYaml: | |
echo "$yaml" | python -c 'import sys, yaml, json; print json.dumps(yaml.load(sys.stdin.read()))' | |
echo | |
echo == Ruby== | |
echo Psych: | |
echo "$yaml" | ruby -e 'require "yaml"; require "json"; puts JSON.dump(YAML.load(STDIN.read))' | |
echo | |
echo == Node.js == | |
echo js-node: | |
echo "$yaml" | node -e 'f = require("fs"); y = require("js-yaml"); console.log(JSON.stringify(y.load(f.readFileSync("/dev/stdin").toString())))' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment