Turtle To JSON-LD Converter - ttl2jsonld.js

Turtle To JSON-LD Converter - ttl2jsonld.js
File Size: 48.4 KB
Views Total: 62
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

ttl2jsonld.js is a JavaScript library that can be used to create a Turtle (Terse RDF Triple Language) to JSON-LD structured data converter.

How to use it:

1. Install & download.

# NPM
$ npm i @frogcat/ttl2jsonld

2. Create a textarea element to accpet Turtle input.

<textarea id="input"></textarea>

3. Create a pre element to display the converter JSON-LD structured data.

<pre id="output">Click 'convert' to run</pre>

4. Create a button to perform the conversion.

<button>Convert</button>

5. Load the ttl2jsonld.js JavaScript library in the document.

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/ttl2jsonld.js"></script>

6. The JavaScript to activate the Turtle To JSON-LD Converter.

$("button").click(function() {
  try {
    var t = $("#input").val();
    var j = ttl2jsonld.parse(t);
    $("#output").text(JSON.stringify(j, null, 2));
  } catch (e) {
    console.log(e);
    alert(e);
  }
});

This awesome jQuery plugin is developed by frogcat. For more Advanced Usages, please check the demo page or visit the official website.