JavaScript YAML Parser

JavascriptHtmlParsingYaml

Javascript Problem Overview


I am looking for a JavaScript YAML parser which converts the YAML into something usable within a HTML page. I've tried this version on Github (https://github.com/visionmedia/js-yaml) but it looks like it only works with node.js

Which libraries should I be using and is there any sample code to show example usage?

Javascript Solutions


Solution 1 - Javascript

JS-YAML parser works in browser. Here is an online demonstration : https://nodeca.github.io/js-yaml. Though, it's primary goal is node.js, and browser version was done just for fun :)

Solution 2 - Javascript

Here is one that I found. Not sure of how much of the spec this meets, but it suited my needs.

https://github.com/jeremyfa/yaml.js

Solution 3 - Javascript

sorry for answering an old post, but I bumped into the same problem as you.

None of the javascript YAML parsers available satisfied my needs so I developed my own: It is available here: http://code.google.com/p/javascript-yaml-parser/

Hope it helps somebody :)

Cumps, Diogo

Solution 4 - Javascript

js-yaml works fine in Safari, Chrome and Firefox on OSX. Here is an example :

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>Test js-yaml</title>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
	<script src="./js-yaml/dist/js-yaml.min.js"></script>
	<script type="text/javascript">

		// YAML string to Javascript object
		var obj = jsyaml.load( 'greeting: hello\nname: world' );
		console.log( obj );

		// YAML file to Javascript object
		$.get( 'https://raw.githubusercontent.com/nodeca/js-yaml/c50f9936bd1e99d64a54d30400e377f4fda401c5/benchmark/samples/document_application2.yaml', function( data ) {
			var obj = jsyaml.load( data );
			console.log( obj );
		});

		// Huge YAML file (7.2 MB) to Javascript object
		$.get( 'https://raw.githubusercontent.com/nodeca/js-yaml/master/benchmark/samples/document_huge.yaml', function( data ) {
			var obj = jsyaml.load( data );
			console.log( obj );
		});

	</script>
</head>
<body>
<h1>Test js-yaml</h1>
<p><a href="https://github.com/nodeca/js-yaml">https://github.com/nodeca/js-yaml</a></p>
</body>
</html>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTomView Question on Stackoverflow
Solution 1 - JavascriptVitalyView Answer on Stackoverflow
Solution 2 - JavascriptmjgilView Answer on Stackoverflow
Solution 3 - JavascriptDiogo CostaView Answer on Stackoverflow
Solution 4 - JavascriptnicoView Answer on Stackoverflow