CINXE.COM

Schema Validation for YAML | JSON Schema Everywhere

<!DOCTYPE html> <html lang="en"><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"><!-- Begin Jekyll SEO tag v2.5.0 --> <title>Schema Validation for YAML | JSON Schema Everywhere</title> <meta name="generator" content="Jekyll v3.7.4" /> <meta property="og:title" content="Schema Validation for YAML" /> <meta property="og:locale" content="en_US" /> <meta name="description" content="Tracking schema validation and editor support of data description languages." /> <meta property="og:description" content="Tracking schema validation and editor support of data description languages." /> <link rel="canonical" href="https://json-schema-everywhere.github.io/yaml" /> <meta property="og:url" content="https://json-schema-everywhere.github.io/yaml" /> <meta property="og:site_name" content="JSON Schema Everywhere" /> <script type="application/ld+json"> {"@type":"WebPage","headline":"Schema Validation for YAML","url":"https://json-schema-everywhere.github.io/yaml","description":"Tracking schema validation and editor support of data description languages.","@context":"http://schema.org"}</script> <!-- End Jekyll SEO tag --> <link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="https://json-schema-everywhere.github.io/feed.xml" title="JSON Schema Everywhere" /><script> if(!(window.doNotTrack === "1" || navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || navigator.msDoNotTrack === "1")) { (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-101483402-1', 'auto'); ga('send', 'pageview'); } </script> </head> <body><header class="site-header" role="banner"> <div class="wrapper"> <a class="site-title" href="/">JSON Schema Everywhere</a> <nav class="site-nav"> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger"> <span class="menu-icon"> <svg viewBox="0 0 18 15" width="18px" height="15px"> <path fill="#424242" d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.031C17.335,0,18,0.665,18,1.484L18,1.484z"/> <path fill="#424242" d="M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0c0-0.82,0.665-1.484,1.484-1.484 h15.031C17.335,6.031,18,6.696,18,7.516L18,7.516z"/> <path fill="#424242" d="M18,13.516C18,14.335,17.335,15,16.516,15H1.484C0.665,15,0,14.335,0,13.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.031C17.335,12.031,18,12.696,18,13.516L18,13.516z"/> </svg> </span> </label> <div class="trigger"> <a class="page-link" href="/cson">CSON</a> <a class="page-link" href="/hjson">Hjson</a> <a class="page-link" href="/json5">JSON5</a> <a class="page-link" href="/toml">TOML</a> <a class="page-link" href="/yaml">YAML</a> </div> </nav> </div> </header> <main class="page-content" aria-label="Content"> <div class="wrapper"> <article class="post"> <header class="post-header"> <a href=http://yaml.org/><img style="float:right;width:160px" src="assets/logos/yaml.svg"></a> <h1 class="post-title">Schema Validation for YAML</h1> </header> <div class="post-content"> <p> JSON Schema can be used to validate YAML documents. <a href=http://yaml.org/>YAML Ain't Markup Language (YAML)</a> is a powerful data serialization language that aims to be human friendly. Most JSON is syntactically valid YAML, but idiomatic YAML follows very different conventions. While YAML has advanced features that cannot be directly mapped to JSON, most YAML files use features that can be validated by JSON Schema. JSON Schema is the most portable and broadly supported choice for YAML validation. </p> <input id="toggle" type="checkbox" style="align:right" unchecked><label style="align:right">Check to see examples of JSON and YAML documents</label> <div id="expand"> <div class="block" style="float:left;width:50%;"> <h3>JSON</h3> <div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">[</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s2">"id"</span><span class="p">:</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s2">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"An ice sculpture"</span><span class="p">,</span><span class="w"> </span><span class="s2">"price"</span><span class="p">:</span><span class="w"> </span><span class="mf">12.5</span><span class="p">,</span><span class="w"> </span><span class="s2">"tags"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="s2">"cold"</span><span class="p">,</span><span class="w"> </span><span class="s2">"ice"</span><span class="w"> </span><span class="p">],</span><span class="w"> </span><span class="s2">"dimensions"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s2">"length"</span><span class="p">:</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="s2">"width"</span><span class="p">:</span><span class="w"> </span><span class="mi">12</span><span class="p">,</span><span class="w"> </span><span class="s2">"height"</span><span class="p">:</span><span class="w"> </span><span class="mf">9.5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s2">"warehouseLocation"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s2">"latitude"</span><span class="p">:</span><span class="w"> </span><span class="mf">-78.75</span><span class="p">,</span><span class="w"> </span><span class="s2">"longitude"</span><span class="p">:</span><span class="w"> </span><span class="mf">20.4</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s2">"id"</span><span class="p">:</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s2">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"A blue mouse"</span><span class="p">,</span><span class="w"> </span><span class="s2">"price"</span><span class="p">:</span><span class="w"> </span><span class="mf">25.5</span><span class="p">,</span><span class="w"> </span><span class="s2">"dimensions"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s2">"length"</span><span class="p">:</span><span class="w"> </span><span class="mf">3.1</span><span class="p">,</span><span class="w"> </span><span class="s2">"width"</span><span class="p">:</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s2">"height"</span><span class="p">:</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s2">"warehouseLocation"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s2">"latitude"</span><span class="p">:</span><span class="w"> </span><span class="mf">54.4</span><span class="p">,</span><span class="w"> </span><span class="s2">"longitude"</span><span class="p">:</span><span class="w"> </span><span class="mf">-32.7</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">]</span><span class="w"> </span></code></pre></div></div> </div> <div class="block" style="float:right;width:50%;"> <h3>YAML</h3> <div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="pi">-</span> <span class="na">id</span><span class="pi">:</span> <span class="s">2</span> <span class="na">name</span><span class="pi">:</span> <span class="s">An ice sculpture</span> <span class="na">price</span><span class="pi">:</span> <span class="s">12.5</span> <span class="na">tags</span><span class="pi">:</span> <span class="pi">-</span> <span class="s">cold</span> <span class="pi">-</span> <span class="s">ice</span> <span class="na">dimensions</span><span class="pi">:</span> <span class="na">length</span><span class="pi">:</span> <span class="s">7</span> <span class="na">width</span><span class="pi">:</span> <span class="s">12</span> <span class="na">height</span><span class="pi">:</span> <span class="s">9.5</span> <span class="na">warehouseLocation</span><span class="pi">:</span> <span class="na">latitude</span><span class="pi">:</span> <span class="s">-78.75</span> <span class="na">longitude</span><span class="pi">:</span> <span class="s">20.4</span> <span class="pi">-</span> <span class="na">id</span><span class="pi">:</span> <span class="s">3</span> <span class="na">name</span><span class="pi">:</span> <span class="s">A blue mouse</span> <span class="na">price</span><span class="pi">:</span> <span class="s">25.5</span> <span class="na">dimensions</span><span class="pi">:</span> <span class="na">length</span><span class="pi">:</span> <span class="s">3.1</span> <span class="na">width</span><span class="pi">:</span> <span class="s">1</span> <span class="na">height</span><span class="pi">:</span> <span class="s">1</span> <span class="na">warehouseLocation</span><span class="pi">:</span> <span class="na">latitude</span><span class="pi">:</span> <span class="s">54.4</span> <span class="na">longitude</span><span class="pi">:</span> <span class="s">-32.7</span> </code></pre></div></div> </div> <small>Example JSON from the <a href="http://json-schema.org/example1.html#set-of-products">JSON Schema</a> website.</small> </div> <br> <h2 id="editors">Editor Support</h2> <table> <tr> <th>Editor</th> <th>Validation</th> <th>Error Highlighting</th> <th>Completion Suggestions</th> </tr> <tr> <td><a href="https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml">Visual Studio Code</a></td> <td> &#x2713; </td> <td> &#x2713; </td> <td> &#x2713; </td> </tr> </table> <h2 id="validators">Tools and Libraries</h2> <ul> <li><a href="https://www.npmjs.com/package/pajv">Polyglottal JSON Schema Validator</a> - Written in JavaScript. Released under the MIT license. <ul> <li>Polyglottal JSON Schema Validator (pajv) is a command line utility that can be used to validate data in numerous formats against a JSON Schema.</li> </ul> </li> </ul> <h2 id="alternatives">Alternatives</h2> <ul> <li><a href="http://www.kuwata-lab.com/kwalify/">Kwalify</a> <ul> <li>Portability concerns with only Ruby and Python implementations</li> </ul> <ul> <li>Only Python has recent development activity</li> </ul> <ul> <li>No tooling support</li> </ul> </ul> </ul> <ul> <li><a href="http://rx.codesimply.com/">Rx</a> <ul> <li>Supports JavaScript, Perl, PHP, Ruby, Python</li> </ul> <ul> <li>No recent development activity</li> </ul> <ul> <li>No tooling support</li> </ul> </ul> </ul> <ul> <li><a href="https://github.com/paazmaya/yaml-validator">yaml-validator</a> <ul> <li>JavaScript only</li> </ul> <ul> <li>Only structural validation</li> </ul> </ul> </ul> <ul> <li><a href="https://github.com/saibotsivad/simple-yaml-validator">simple-yaml-validator</a> <ul> <li>JavaScript only</li> </ul> <ul> <li>Only structural validation</li> </ul> <ul> <li>Little adoption. npm shows low download count.</li> </ul> </ul> </ul> <ul> <li><a href="https://pypi.python.org/pypi/yamale">Yamale</a> <ul> <li>Python only</li> </ul> <ul> <li>Relatively unknown</li> </ul> </ul> </ul> </div> </article> </div> </main><footer class="site-footer"> <div class="wrapper"> <div class="footer-col-wrapper"> <div class="footer-col footer-col-1"> <h2 class="footer-heading"><a href="/">JSON Schema Everywhere</a></h2> <ul class="contact-list"> <li> Tracking schema validation and editor support of data description languages. </li> <a href="https://github.com/json-schema-everywhere"><span class="icon icon--github"><svg viewBox="0 0 16 16" width="16px" height="16px"><path fill="#828282" d="M7.999,0.431c-4.285,0-7.76,3.474-7.76,7.761 c0,3.428,2.223,6.337,5.307,7.363c0.388,0.071,0.53-0.168,0.53-0.374c0-0.184-0.007-0.672-0.01-1.32 c-2.159,0.469-2.614-1.04-2.614-1.04c-0.353-0.896-0.862-1.135-0.862-1.135c-0.705-0.481,0.053-0.472,0.053-0.472 c0.779,0.055,1.189,0.8,1.189,0.8c0.692,1.186,1.816,0.843,2.258,0.645c0.071-0.502,0.271-0.843,0.493-1.037 C4.86,11.425,3.049,10.76,3.049,7.786c0-0.847,0.302-1.54,0.799-2.082C3.768,5.507,3.501,4.718,3.924,3.65 c0,0,0.652-0.209,2.134,0.796C6.677,4.273,7.34,4.187,8,4.184c0.659,0.003,1.323,0.089,1.943,0.261 c1.482-1.004,2.132-0.796,2.132-0.796c0.423,1.068,0.157,1.857,0.077,2.054c0.497,0.542,0.798,1.235,0.798,2.082 c0,2.981-1.814,3.637-3.543,3.829c0.279,0.24,0.527,0.713,0.527,1.437c0,1.037-0.01,1.874-0.01,2.129 c0,0.208,0.14,0.449,0.534,0.373c3.081-1.028,5.302-3.935,5.302-7.362C15.76,3.906,12.285,0.431,7.999,0.431z"/></svg> </span><span class="username">json-schema-everywhere</span></a> </ul> <ul class="social-media-list"> </ul> </div> <div class="footer-col footer-col-2"> </div> <div class="footer-col footer-col-3"> <p> The content of this site is licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 License</a>.<br> All logos and trademarks are property of their respective owners.<br> <a href="https://github.com/json-schema-everywhere/json-schema-everywhere.github.io/"><small>Hosted on GitHub</small></a> </p> </div> </div> </div> </footer> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10