View Source README

JSON-LD.ex
An implementation of the JSON-LD standard for Elixir and RDF.ex.
The API documentation can be found here. For a guide and more information about RDF.ex and it's related projects, go to https://rdf-elixir.dev.
features
Features
- fully conforming JSON-LD 1.0 API processor
- JSON-LD reader/writer for RDF.ex
- tests of the JSON-LD test suite (see here for a detailed status report)
todo
TODO
- JSON-LD Framing
- JSON-LD 1.1 support
installation
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
Usage
expand-a-document
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
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
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")
When a context is provided via the :context
option (as a map, a RDF.PropertyMap
or a string with a URL to a remote context), the document gets automatically compacted on serialization.
JSON.LD.write_file!(dataset, "file.jsonld", context: %{ex: "https://example.com/"})
JSON.LD.write_file!(dataset, "file.jsonld", context: "https://schema.org/")
pretty-printing
Pretty printing
Pretty printing is possible on all writer functions with all 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"])
contributing
Contributing
see CONTRIBUTING for details.
consulting
Consulting
If you need help with your Elixir and Linked Data projects, just contact NinjaConcept via contact@ninjaconcept.com.
license-and-copyright
License and Copyright
(c) 2017-present Marcel Otto. MIT Licensed, see LICENSE for details.