2.9 KiB
2.9 KiB
JSON-LD.ex
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
- remote contexts
- JSON-LD Framing
- JSON-LD 1.1 support
Installation
JSON-LD.ex can be installed as usual:
- Add
json_ld
to your list of dependencies inmix.exs
:
def deps do
[{:json_ld, "~> 0.1.0"}]
end
- Ensure
rdf
is started before your application:
def application do
[applications: [:json_ld]]
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.
License and Copyright
(c) 2017 Marcel Otto. MIT Licensed, see LICENSE for details.