Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An implementation of JSON-LD for Elixir

License

NotificationsYou must be signed in to change notification settings

rdf-elixir/jsonld-ex

Repository files navigation

JSON-LD-logo-64

JSON-LD.ex

Hex.pmHex DocsCoverage StatusTotal DownloadLicense

ExUnit TestsDialyzerQuality Checks

An implementation of theJSON-LD 1.1 standard for Elixir andRDF.ex.

The API documentation can be foundhere. For a guide and more information about RDF.ex and it's related projects, go tohttps://rdf-elixir.dev.

Features

  • fully conforming JSON-LD 1.1 API processor
  • JSON-LD reader/writer forRDF.ex
  • customizable HTTP client for remote document loading
  • tests of theJSON-LD test suite (seehere for the EARL reports)

TODO

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")

When a context is provided via the:context option (as a map, aRDF.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 is possible on all writer functions with all the formatter options ofJason, 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

seeCONTRIBUTING for details.

Consulting

If you need help with your Elixir and Linked Data projects, just contactNinjaConcept viacontact@ninjaconcept.com.

Acknowledgements

NLnet Foundation LogoNGI0 LogoJetBrains Logo

This project is partly funded throughNGI0 Commons Fund, a fund established byNLnet with financial support from the European Commission'sNext Generation Internet program.

JetBrains supports the project with complimentary access to its development environments.

License and Copyright

(c) 2017-present Marcel Otto. MIT Licensed, seeLICENSE for details.

About

An implementation of JSON-LD for Elixir

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors7


[8]ページ先頭

©2009-2025 Movatter.jp