Go to file
2018-03-13 00:56:32 +01:00
config json_ld: mix new json_ld --module JSON.LD 2016-12-08 00:27:27 +01:00
lib Add handling of RDF.Graphs and RDF.Descriptions to JSON.LD.Encoder 2018-03-13 00:56:32 +01:00
test Add handling of RDF.Graphs and RDF.Descriptions to JSON.LD.Encoder 2018-03-13 00:56:32 +01:00
.editorconfig Add .editorconfig 2017-06-25 02:06:24 +02:00
.gitignore json_ld: mix new json_ld --module JSON.LD 2016-12-08 00:27:27 +01:00
.travis.yml Add Elixir 1.6 to TravisCI 2018-01-27 23:34:12 +01:00
CHANGELOG.md Add handling of RDF.Graphs and RDF.Descriptions to JSON.LD.Encoder 2018-03-13 00:56:32 +01:00
CODE_OF_CONDUCT.md Add CODE_OF_CONDUCT 2017-06-25 02:07:04 +02:00
CONTRIBUTING.md Add CONTRIBUTING.md 2017-06-25 20:19:26 +02:00
LICENSE.md Update copyright 2017-06-25 02:06:43 +02:00
mix.exs Upgrade to RDF.ex 0.4.0 2018-03-10 01:58:43 +01:00
mix.lock Upgrade to RDF.ex 0.4.0 2018-03-10 01:58:43 +01:00
README.md Prepare release 0.2.0 2017-08-24 19:13:47 +02:00
VERSION Add handling of RDF.Graphs and RDF.Descriptions to JSON.LD.Encoder 2018-03-13 00:56:32 +01:00

JSON-LD.ex

Travis Hex.pm Coverage Status

An implementation of the JSON-LD standard for Elixir and RDF.ex.

Features

  • fully conforming JSON-LD API processor
  • JSON-LD reader/writer for RDF.ex
  • tests of the JSON-LD test suite (see here for a detailed status report)

TODO

Installation

The JSON-LD.ex Hex package can be installed as usual, by adding json_ld to your list of dependencies in mix.exs:

def deps do
  [{:json_ld, "~> 0.2"}]
end

Usage

Expand a document

"""
{
 "@context":
 {
    "name": "http://xmlns.com/foaf/0.1/name",
    "homepage": {
      "@id": "http://xmlns.com/foaf/0.1/homepage",
      "@type": "@id"
    }
 },
 "name": "Manu Sporny",
 "homepage": "http://manu.sporny.org/"
}
"""
|> Poison.Parser.parse!
|> JSON.LD.expand

produces

[%{"http://xmlns.com/foaf/0.1/homepage" => [%{"@id" => "http://manu.sporny.org/"}],
   "http://xmlns.com/foaf/0.1/name" => [%{"@value" => "Manu Sporny"}]}]

Compact a document

context = Poison.Parser.parse! """
  {
    "@context": {
      "name": "http://xmlns.com/foaf/0.1/name",
      "homepage": {
        "@id": "http://xmlns.com/foaf/0.1/homepage",
        "@type": "@id"
      }
    }
  }
  """

"""
[
  {
    "http://xmlns.com/foaf/0.1/name": [ "Manu Sporny" ],
    "http://xmlns.com/foaf/0.1/homepage": [
      {
       "@id": "http://manu.sporny.org/"
      }
    ]
  }
]
"""
|> Poison.Parser.parse!
|> JSON.LD.compact(context)

produces

%{"@context" => %{
    "homepage" => %{
        "@id" => "http://xmlns.com/foaf/0.1/homepage", 
        "@type" => "@id"},
    "name" => "http://xmlns.com/foaf/0.1/name"
    },
  "homepage" => "http://manu.sporny.org/", 
  "name" => "Manu Sporny"}

RDF Reader and Writer

JSON-LD.ex can be used to serialize or deserialize RDF graphs by using it as a RDF.ex reader and writer.

dataset = JSON.LD.read_file!("file.jsonld")
JSON.LD.write_file!(dataset, "file.jsonld")

Getting help

Contributing

see CONTRIBUTING for details.

(c) 2017 Marcel Otto. MIT Licensed, see LICENSE for details.