How to parse YAML in the browser? [duplicate]
I would like to parse YAML in the browser. Ideally I’m looking for a browser-ready library. The ones I’ve found are not written to run in a browser (they make synchronous calls to require()
or assume the existence of an exports
variable).
Alternatively, I’ll accept example code that shows how to load a YAML-parsing library into the browser via RequireJS.
Similar question: JavaScript YAML Parser.
The most promising library that seems to work in the browser is js-yaml. A snippet from the project page for loading the library in HTML:
<script src="https://stackoverflow.com/questions/9043765/js-yaml.min.js"></script>
<script type="text/javascript">
var doc = jsyaml.load('greeting: hello\nname: world');
</script>
They claim to also support AMD loaders like RequireJS.
Here is the “browserified” version of the library: with comments and minified.
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .