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: 5 days 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 (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-09-09T17:50:48.000Z (about 2 months ago)
- Last Synced: 2024-09-09T21:58:28.316Z (about 2 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
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Build Status](https://app.travis-ci.com/ropensci/jsonld.svg?branch=master)](https://app.travis-ci.com/ropensci/jsonld)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/ropensci/jsonld?branch=master&svg=true)](https://ci.appveyor.com/project/jeroen/jsonld)
[![Coverage Status](https://codecov.io/github/ropensci/jsonld/coverage.svg?branch=master)](https://app.codecov.io/github/ropensci/jsonld?branch=master)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/jsonld)](https://cran.r-project.org/package=jsonld)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/jsonld)](https://cran.r-project.org/package=jsonld)
[![Github Stars](https://img.shields.io/github/stars/ropensci/jsonld.svg?style=social&label=Github)](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 .
```