Javascript RDF/Turtle Parser

RDF/Turtleをパースして、トリプルをJavascript/JSONの配列として返します。Jim LeyのJavascript RDF Parserと同じフォーマットなので、少しの変更でその関数が利用できます。また、TurtleをJSON形式に変換することもできます。

Parses RDF/Turtle string and generates Javascript/JSON array of RDF triples, which is the same format as that of Jim Ley's Javascript RDF Parser. So you can use Jim's utilities with this output (need to add a few lines to his script so that it accepts calls from outside). Optionally, converts RDF/Turtle into similar form of JSON.

Now it passes most Tuttle test cases, but, of course, not perfect. Feedback welcome.

Example 1: FOAF

You can above RDF/Turtle. Note that extra triple [:nick "libby"] will be added with Jim's doSubProperties function (doesn't work with Safari ??).

So, find where = (even though source Turtle doesn't have matching triple).

It's also possible to convert from and convert resulting (can only convert first bnode that corresponds to JSON object model, excluding the last rdfs:subPropertyOf triple).

Example 2: RSS

Converrt and/or find from pseudo RSS 1.0 feed fragment.

This time, try to find all where =


Turtle to JSON

Parse Turtle and Turtle to JSON conversion uses turtle.js script. parse() function returns array of triples. parse_to_json() function returns a JSON object.


// initialize
var turtle = new ParseTurtle;

// get RDF triples as a javascript array
var rdf = turtle.parse(turtle_string);

// or convert Turtle string to similar JSON (javascript) object
var json = turtle.parse_to_json(turtle_string);

Javascript (JSON) array/objct dump is made possible with JKL.Dumper written by Y. Kawasaki.

JSON to Turtle

JSON to Turtle conversion uses json-turtle.js script. parsej(j,sep,pre) function takes JSON object, result line break, and result indent as parameters, and returns Turtle string. There is a covenient function j2t() function that takes input and output field id of XHTML form as parameter..


// initialize
var json = new JsonTurtle;

// parse JSON object and returns Turtle string
var turtle_string = json.parsej(json_object,"\n",'');

// or use easy way to test with XHTML form textarea
json.j2t(input_fld_id, output_fld_id);

JSON/Turtle conversion has following arbitrary mapping:

  • Top blank node of Turtle is mapped to JSON object.
  • Namespace prefixes are mapped to equivallent JSON property in top level.
  • Repeated properties are mapped to JSON array.
  • If Turtle has a subject URI, it will be mapped to JSON "@about" property.

Cannot get nice result for some complex data, yet :-( There is a series of Japanese introduction to JSON and Turtle.

Known bugs