{"id":13556027,"url":"https://github.com/levelgraph/levelgraph-jsonld","last_synced_at":"2025-12-12T05:49:18.130Z","repository":{"id":39380754,"uuid":"11437125","full_name":"levelgraph/levelgraph-jsonld","owner":"levelgraph","description":"The Object Document Mapper for LevelGraph based on JSON-LD","archived":false,"fork":false,"pushed_at":"2023-06-23T05:56:18.000Z","size":567,"stargazers_count":113,"open_issues_count":22,"forks_count":16,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-09T00:48:45.640Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/levelgraph.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-16T00:44:38.000Z","updated_at":"2023-03-23T03:19:43.000Z","dependencies_parsed_at":"2024-08-01T12:40:48.112Z","dependency_job_id":null,"html_url":"https://github.com/levelgraph/levelgraph-jsonld","commit_stats":null,"previous_names":["mcollina/levelgraph-jsonld"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levelgraph%2Flevelgraph-jsonld","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levelgraph%2Flevelgraph-jsonld/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levelgraph%2Flevelgraph-jsonld/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levelgraph%2Flevelgraph-jsonld/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/levelgraph","download_url":"https://codeload.github.com/levelgraph/levelgraph-jsonld/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244554132,"owners_count":20471173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:03:34.481Z","updated_at":"2025-12-12T05:49:13.088Z","avatar_url":"https://github.com/levelgraph.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"LevelGraph-JSONLD\n===========\n\n![Logo](https://github.com/levelgraph/levelgraph/raw/master/logo.png)\n\n[![Build Status](https://travis-ci.org/levelgraph/levelgraph-jsonld.png)](https://travis-ci.org/levelgraph/levelgraph-jsonld)\n[![Coverage Status](https://coveralls.io/repos/levelgraph/levelgraph-jsonld/badge.png)](https://coveralls.io/r/levelgraph/levelgraph-jsonld)\n[![Dependency Status](https://david-dm.org/levelgraph/levelgraph-jsonld.png?theme=shields.io)](https://david-dm.org/levelgraph/levelgraph-jsonld)\n[![Sauce Labs Tests](https://saucelabs.com/browser-matrix/levelgraph-jsonld.svg)](https://saucelabs.com/u/levelgraph-jsonld)\n\n__LevelGraph-JSONLD__ is a plugin for\n[LevelGraph](http://github.com/levelgraph/levelgraph) that adds the\nability to store, retrieve and delete JSON-LD objects.\nIn fact, it is a full-blown Object-Document-Mapper (ODM) for\n__LevelGraph__.\n\n## Install\n\n### Node.js\n\nAdding support for JSON-LD to LevelGraph is easy:\n```shell\n$ npm install level levelgraph levelgraph-jsonld --save\n```\nThen in your code:\n```javascript\nvar level      = require('level'),\n    yourDB     = level('./yourdb'),\n    levelgraph = require('levelgraph'),\n    jsonld     = require('levelgraph-jsonld'),\n    db         = jsonld(levelgraph(yourDB));\n```\n\nAt the moment it requires node v0.10.x, but the port to node v0.8.x\nshould be straighforward.\nIf you need it, just open a pull request.\n\n## Browser\n\nIf you use [browserify](http://browserify.org/) you can use this package\nin a browser just as in node.js. Please also take a look at [Browserify\nsection in LevelGraph package](https://github.com/levelgraph/levelgraph#browserify)\n\nYou can also use standalone browserified version from `./build`\ndirectory or use [bower](http://bower.io)\n\n```shell\n$ bower install levelgraph-jsonld --save\n```\nIt will also install its dependency levelgraph! Now you can simply:\n\n```html\n\u003cscript src=\"bower_components/levelgraph/build/levelgraph.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"bower_components/levelgraph-jsonld/build/levelgraph-jsonld.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  var db = levelgraphJSONLD(levelgraph('yourdb'));\n\u003c/script\u003e\n```\n\n## Usage\n\nWe assume in following examples that you created database as explained\nabove!\n```js\nvar level  = require('level'),\n    yourDB = level('./yourdb'),\n    db     = levelgraphJSONLD(levelgraph(yourDB));\n```\n\n`'base'` can also be specified when you create the db:\n```javascript\nvar level      = require('level'),\n    yourDB     = level('./yourdb'),\n    levelgraph = require('levelgraph'),\n    jsonld     = require('levelgraph-jsonld'),\n    opts       = { base: 'http://matteocollina.com/base' },\n    db         = jsonld(levelgraph(yourDB), opts);\n```\n\n\u003e From v1, overwriting and deleting is more conservative. If you rely on the previous behavior you can set the `overwrite` option to `true` (when creating the db or as options to `put` and `del`) to:\n\u003e  - overwrite all existing triples when using `put`\n\u003e  - delete all blank nodes recursively when using `del` (cf upcoming `cut` function)\n\u003e This old api will be phased out.\n\n### Put\n\nPlease keep in mind that LevelGraph-JSONLD __doesn't store the original\nJSON-LD document but decomposes it into triples__! It stores literals\ndouble quoted with datatype if other then string. If you use plain\nLevelGraph methods, instead trying to match number `42` you need to try\nmatching `\"42\"^^http://www.w3.org/2001/XMLSchema#integer`\n\n Storing triples from JSON-LD document is extremely easy:\n```javascript\nvar manu = {\n  \"@context\": {\n    \"name\": \"http://xmlns.com/foaf/0.1/name\",\n    \"homepage\": {\n      \"@id\": \"http://xmlns.com/foaf/0.1/homepage\",\n      \"@type\": \"@id\"\n    }\n  },\n  \"@id\": \"http://manu.sporny.org#person\",\n  \"name\": \"Manu Sporny\",\n  \"homepage\": \"http://manu.sporny.org/\"\n};\n\ndb.jsonld.put(manu, function(err, obj) {\n  // do something after the obj is inserted\n});\n```\n\nif the top level objects have no `'@id'` key, one will be generated for\neach, using a UUID and the `'base'` argument, like so:\n```javascript\ndelete manu['@id'];\ndb.jsonld.put(manu, { base: 'http://this/is/an/iri' }, function(err, obj) {\n  // obj['@id'] will be something like\n  // http://this/is/an/iri/b1e783b0-eda6-11e2-9540-d7575689f4bc\n});\n```\n\n`'base'` can also be [specified when you create the db](#usage).\n\n__LevelGraph-JSONLD__ also support nested objects, like so:\n```javascript\nvar nested = {\n  \"@context\": {\n    \"name\": \"http://xmlns.com/foaf/0.1/name\",\n    \"knows\": \"http://xmlns.com/foaf/0.1/knows\"\n  },\n  \"@id\": \"http://matteocollina.com\",\n  \"name\": \"Matteo\",\n  \"knows\": [{\n    \"name\": \"Daniele\"\n  }, {\n    \"name\": \"Lucio\"\n  }]\n};\n\ndb.jsonld.put(nested, function(err, obj) {\n  // do something...\n});\n```\n\n### Get\n\nRetrieving a JSON-LD object from the store requires its `'@id'`:\n```javascript\ndb.jsonld.get(manu['@id'], { '@context': manu['@context'] }, function(err, obj) {\n  // obj will be the very same of the manu object\n});\n```\n\nThe format of the loaded object is entirely specified by the\n`'@context'`, so have fun :).\n\nAs with `'put'` it correctly support nested objects. If nested objects didn't originally include `'@id'` properties, now they will have them since `'put'` generates them by using UUID and formats\nthem as *blank node identifiers*:\n```javascript\nvar nested = {\n  \"@context\": {\n    \"name\": \"http://xmlns.com/foaf/0.1/name\",\n    \"knows\": \"http://xmlns.com/foaf/0.1/knows\"\n  },\n  \"@id\": \"http://matteocollina.com\",\n  \"name\": \"Matteo\",\n  \"knows\": [{\n    \"name\": \"Daniele\"\n  }, {\n    \"name\": \"Lucio\"\n  }]\n};\n\ndb.jsonld.put(nested, function(err, obj) {\n  // obj will be\n  // {\n  //   \"@context\": {\n  //     \"name\": \"http://xmlns.com/foaf/0.1/name\",\n  //     \"knows\": \"http://xmlns.com/foaf/0.1/knows\"\n  //   },\n  //   \"@id\": \"http://matteocollina.com\",\n  //   \"name\": \"Matteo\",\n  //   \"knows\": [{\n  //     \"@id\": \"_:7053c150-5fea-11e3-a62e-adadc4e3df79\",\n  //     \"name\": \"Daniele\"\n  //   }, {\n  //     \"@id\": \"_:9d2bb59d-3baf-42ff-ba5d-9f8eab34ada5\",\n  //     \"name\": \"Lucio\"\n  //   }]\n  // }\n});\n```\n\n### Delete\n\nIn order to delete an object, you need to pass the document to the `'del'` method which will delete only the properties specified in the document:\n```javascript\ndb.jsonld.del(manu, function(err) {\n  // do something after it is deleted!\n});\n```\n\nNote that blank nodes are ignored, so to delete blank nodes you need to pass the `cut: true` option (you can also add the `recurse: true`option) or use the `'cut'` method below.\n\n\u003e Note that since v1 `'del'` doesn't support passing an IRI anymore.\n\n### Cut\n\nIn order to delete the blank nodes object, you can just pass it's `'@id'` to the\n`'cut'` method:\n```javascript\ndb.jsonld.cut(manu['@id'], function(err) {\n  // do something after it is cut!\n});\n```\n\nYou can also pass an object, but in this case the properties are not used to determine which triples will be deleted and only the `@id`s are considered.\n\nUsing the `recurse` option you can follow all links and blank nodes (which might result in deleting more data than you expect)\n```javascript\ndb.jsonld.cut(manu['@id'], { recurse: true }, function(err) {\n  // do something after it is cut!\n});\n```\n\n### Searching with LevelGraph\n\n__LevelGraph-JSONLD__ does not support searching for objects, because\nthat problem is already solved by __LevelGraph__ itself. This example\nsearch finds friends living near Paris:\n```javascript\nvar manu = {\n  \"@context\": {\n    \"@vocab\": \"http://xmlns.com/foaf/0.1/\",\n    \"homepage\": { \"@type\": \"@id\" },\n    \"knows\": { \"@type\": \"@id\" },\n    \"based_near\": { \"@type\": \"@id\" }\n  },\n  \"@id\": \"http://manu.sporny.org#person\",\n  \"name\": \"Manu Sporny\",\n  \"homepage\": \"http://manu.sporny.org/\",\n  \"knows\": [{\n    \"@id\": \"https://my-profile.eu/people/deiu/card#me\",\n    \"name\": \"Andrei Vlad Sambra\",\n    \"based_near\": \"http://dbpedia.org/resource/Paris\"\n  }, {\n    \"@id\": \"http://melvincarvalho.com/#me\",\n    \"name\": \"Melvin Carvalho\",\n    \"based_near\": \"http://dbpedia.org/resource/Honolulu\"\n  }, {\n    \"@id\": \"http://bblfish.net/people/henry/card#me\",\n    \"name\": \"Henry Story\",\n    \"based_near\": \"http://dbpedia.org/resource/Paris\"\n  }, {\n    \"@id\": \"http://presbrey.mit.edu/foaf#presbrey\",\n    \"name\": \"Joe Presbrey\",\n    \"based_near\": \"http://dbpedia.org/resource/Cambridge\"\n  }]\n};\n\nvar paris = 'http://dbpedia.org/resource/Paris';\n\ndb.jsonld.put(manu, function(){\n  db.search([{\n    subject: manu['@id'],\n    predicate: 'http://xmlns.com/foaf/0.1/knows',\n    object: db.v('webid')\n  }, {\n    subject: db.v('webid'),\n    predicate: 'http://xmlns.com/foaf/0.1/based_near',\n    object: paris\n  }, {\n    subject: db.v('webid'),\n    predicate: 'http://xmlns.com/foaf/0.1/name',\n    object: db.v('name')\n  }\n  ], function(err, solution) {\n    // solution contains\n    // [{\n    //   webid: 'http://bblfish.net/people/henry/card#me',\n    //   name: '\"Henry Story\"'\n    // }, {\n    //   webid: 'https://my-profile.eu/people/deiu/card#me',\n    //   name: '\"Andrei Vlad Sambra\"'\n    // }]\n  });\n});\n```\n## Changes\n\n[CHANGELOG.md](https://github.com/levelgraph/levelgraph-jsonld/blob/master/CHANGELOG.md)\n**including migration info for breaking changes**\n\n\n## Contributing to LevelGraph-JSONLD\n\n* Check out the latest master to make sure the feature hasn't been\n  implemented or the bug hasn't been fixed yet\n* Check out the issue tracker to make sure someone already hasn't\n  requested it and/or contributed it\n* Fork the project\n* Start a feature/bugfix branch\n* Commit and push until you are happy with your contribution\n* Make sure to add tests for it. This is important so I don't break it\n  in a future version unintentionally.\n* Please try not to mess with the Makefile and package.json. If you\n  want to have your own version, or is otherwise necessary, that is\n  fine, but please isolate to its own commit so I can cherry-pick around\n  it.\n\n## LICENSE - \"MIT License\"\n\nCopyright (c) 2013-2017 Matteo Collina and LevelGraph-JSONLD contributors\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevelgraph%2Flevelgraph-jsonld","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevelgraph%2Flevelgraph-jsonld","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevelgraph%2Flevelgraph-jsonld/lists"}