Turtle To JSON-LD Converter - ttl2jsonld.js

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

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);
  }
});

Changelog:

v0.0.9 (2023-01-30)

  • Fix behavior when prefix in JSON-LD context is not absolute URI

v0.0.8 (2022-03-27)

  • Update dev dependencies

v0.0.7 (2022-02-17)

  • Passed positive_numeric
  • Passed numeric_with_leading_0
  • Passed turtle-subm-11

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