Go to file
Marcel Otto 1c989b6294 Disable warnings-as-error on CI temporarily
This needs a fix of the RDF.Serialization.Encoder behaviour in the next
RDF.ex version.
2021-11-22 22:24:12 +01:00
.github/workflows Disable warnings-as-error on CI temporarily 2021-11-22 22:24:12 +01:00
config json_ld: mix new json_ld --module JSON.LD 2016-12-08 00:27:27 +01:00
lib Fix processing of remote contexts with a list 2021-08-19 15:43:59 +02:00
priv/plts Run Dialyzer in CI 2020-06-22 01:44:57 +02:00
test Test: use Bypass for remote context test (#8) 2021-08-19 22:29:57 +02:00
.editorconfig Add .editorconfig 2017-06-25 02:06:24 +02:00
.formatter.exs Apply mix formatter 2020-06-20 04:25:58 +02:00
.gitignore Run Dialyzer in CI 2020-06-22 01:44:57 +02:00
.iex.exs Adapt to new RDF.ex literal datatype system 2020-05-07 17:21:12 +02:00
CHANGELOG.md Fix processing of remote contexts with a list 2021-08-19 15:43:59 +02:00
CODE_OF_CONDUCT.md Add CODE_OF_CONDUCT 2017-06-25 02:07:04 +02:00
CONTRIBUTING.md Update contribution guidelines 2020-06-22 01:29:32 +02:00
LICENSE.md Prepare release 0.3.1 2020-06-01 21:44:16 +02:00
mix.exs Include CHANGELOG in API documentation 2021-08-20 18:44:08 +02:00
mix.lock Remove unused earmark dependency 2021-11-22 22:00:37 +01:00
README.md Move from Travis CI to GitHub Actions 2020-10-13 16:44:29 +02:00
VERSION Prepare release 0.3.3 2020-10-13 17:00:37 +02:00

JSON-LD-logo-64

JSON-LD.ex

CI 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.3"}]
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/"
}
"""
|> Jason.decode!
|> 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 = Jason.decode! """
  {
    "@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/"
      }
    ]
  }
]
"""
|> Jason.decode!
|> 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")

Pretty printing

Pretty printing is possible on all writer functions with all of the formatter options of Jason, the underlying JSON encoder, to which the given options are passed through.

JSON.LD.write_file!(dataset, "file.jsonld", pretty: true)
JSON.LD.write_string(dataset, "file.jsonld", pretty: [indent: "\t"])

Getting help

Contributing

see CONTRIBUTING for details.

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