Created
September 30, 2010 18:22
-
-
Save thisismedium/605051 to your computer and use it in GitHub Desktop.
Evaluate a YAML document in Node.JS using Python.
This file contains hidden or 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
// Evaluate a YAML document. | |
// | |
// + text - String YAML document | |
// + next - Function callback | |
// | |
// For example: | |
// | |
// loadYAML("this: is\nyaml:", function(err, obj) { | |
// if (err) throw err; | |
// console.dir(obj); | |
// }); | |
// | |
// Returns nothing. | |
function loadYAML(text, next) { | |
var exec = require('child_process').exec, | |
script = 'import json, yaml, sys; json.dump(yaml.load(sys.stdin), sys.stdout)', | |
py = exec("python -c '" + script + "'", function(err, stdout, stderr) { | |
err ? next(err) : next(null, JSON.parse(stdout)); | |
}); | |
py.stdin.end(text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment