Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ropensci/jsonld
R wrapper for jsonld.js JavaScript library
https://github.com/ropensci/jsonld
json-ld r r-package rstats
Last synced: 4 months ago
JSON representation
R wrapper for jsonld.js JavaScript library
- Host: GitHub
- URL: https://github.com/ropensci/jsonld
- Owner: ropensci
- License: other
- Created: 2016-12-06T15:10:25.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-09-09T17:50:48.000Z (5 months ago)
- Last Synced: 2024-09-09T21:58:28.316Z (5 months ago)
- Topics: json-ld, r, r-package, rstats
- Language: R
- Homepage: https://docs.ropensci.org/jsonld
- Size: 369 KB
- Stars: 35
- Watchers: 8
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - ropensci/jsonld - R wrapper for jsonld.js JavaScript library (R)
README
# jsonld
> JSON for Linking Data
[](https://www.repostatus.org/#active)
[](https://app.travis-ci.com/ropensci/jsonld)
[](https://ci.appveyor.com/project/jeroen/jsonld)
[](https://app.codecov.io/github/ropensci/jsonld?branch=master)
[](https://cran.r-project.org/package=jsonld)
[](https://cran.r-project.org/package=jsonld)
[](https://github.com/ropensci/jsonld)JSON-LD is a light-weight syntax for expressing linked data. It is primarily
intended for web-based programming environments, interoperable web services and for
storing linked data in JSON-based databases. This package provides bindings to the
JavaScript library for converting, expanding and compacting JSON-LD documents.## Hello World
Example from https://github.com/digitalbazaar/jsonld.js#quick-examples. Example data:
```r
doc <- '{
"http://schema.org/name": "Manu Sporny",
"http://schema.org/url": {"@id": "http://manu.sporny.org/"},
"http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.png"}
}'context <- '{
"name": "http://schema.org/name",
"homepage": {"@id": "http://schema.org/url", "@type": "@id"},
"image": {"@id": "http://schema.org/image", "@type": "@id"}
}'
```### Compact and expand:
```r
(out <- jsonld_compact(doc, context))
``````
{
"@context": {
"name": "http://schema.org/name",
"homepage": {
"@id": "http://schema.org/url",
"@type": "@id"
},
"image": {
"@id": "http://schema.org/image",
"@type": "@id"
}
},
"image": "http://manu.sporny.org/images/manu.png",
"name": "Manu Sporny",
"homepage": "http://manu.sporny.org/"
}
``````r
(expanded <- jsonld_expand(out))
``````
[
{
"http://schema.org/url": [
{
"@id": "http://manu.sporny.org/"
}
],
"http://schema.org/image": [
{
"@id": "http://manu.sporny.org/images/manu.png"
}
],
"http://schema.org/name": [
{
"@value": "Manu Sporny"
}
]
}
]
```### Convert between JSON and RDF:
```r
cat(nquads <- jsonld_to_rdf(doc))
``````
_:b0 .
_:b0 "Manu Sporny" .
_:b0 .
``````r
jsonld_from_rdf(nquads)
``````
[
{
"@id": "_:b0",
"http://schema.org/image": [
{
"@id": "http://manu.sporny.org/images/manu.png"
}
],
"http://schema.org/name": [
{
"@value": "Manu Sporny"
}
],
"http://schema.org/url": [
{
"@id": "http://manu.sporny.org/"
}
]
}
]
```### Other utilities:
```r
jsonld_flatten(doc)
``````
[
{
"@id": "_:b0",
"http://schema.org/image": [
{
"@id": "http://manu.sporny.org/images/manu.png"
}
],
"http://schema.org/name": [
{
"@value": "Manu Sporny"
}
],
"http://schema.org/url": [
{
"@id": "http://manu.sporny.org/"
}
]
}
]
``````r
cat(jsonld_normalize(doc, algorithm = 'URDNA2015', format = 'application/nquads'))
``````
_:c14n0 .
_:c14n0 "Manu Sporny" .
_:c14n0 .
```