JavaScript YAML Parser [closed]

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?

Answers:

Answer

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

Answer

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

Answer

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

Answer

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>

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.