{"id":32991148,"url":"https://github.com/D2KLab/sparql-transformer","last_synced_at":"2025-11-15T10:01:12.463Z","repository":{"id":29243189,"uuid":"116024465","full_name":"D2KLab/sparql-transformer","owner":"D2KLab","description":"A more handy way to use SPARQL data in your web app","archived":false,"fork":false,"pushed_at":"2024-08-29T14:05:17.000Z","size":873,"stargazers_count":47,"open_issues_count":8,"forks_count":6,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-09-04T13:51:43.915Z","etag":null,"topics":["json-ld","linked-data","sparql","sparql-transformer","transformer"],"latest_commit_sha":null,"homepage":"https://d2klab.github.io/sparql-transformer/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/D2KLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-01-02T14:37:28.000Z","updated_at":"2025-07-07T15:39:47.000Z","dependencies_parsed_at":"2024-01-06T13:09:18.730Z","dependency_job_id":"b6f7cb85-8c00-452c-a728-f3c774dceac5","html_url":"https://github.com/D2KLab/sparql-transformer","commit_stats":{"total_commits":132,"total_committers":6,"mean_commits":22.0,"dds":"0.11363636363636365","last_synced_commit":"133137f0212638cd94f698af0ed760f33043ea5f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/D2KLab/sparql-transformer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D2KLab%2Fsparql-transformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D2KLab%2Fsparql-transformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D2KLab%2Fsparql-transformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D2KLab%2Fsparql-transformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/D2KLab","download_url":"https://codeload.github.com/D2KLab/sparql-transformer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D2KLab%2Fsparql-transformer/sbom","scorecard":{"id":34954,"data":{"date":"2025-08-11","repo":{"name":"github.com/D2KLab/sparql-transformer","commit":"af042fbf22505928c8df34efca1f86ca8f3e0047"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2,"checks":[{"name":"Code-Review","score":2,"reason":"Found 6/29 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 7 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"13 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx","Warn: Project is vulnerable to: GHSA-8hc4-vh64-cxmj","Warn: Project is vulnerable to: GHSA-jr5f-v2jv-69x6","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-14T20:06:34.528Z","repository_id":29243189,"created_at":"2025-08-14T20:06:34.529Z","updated_at":"2025-08-14T20:06:34.529Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284538091,"owners_count":27022334,"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","status":"online","status_checked_at":"2025-11-15T02:00:06.050Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["json-ld","linked-data","sparql","sparql-transformer","transformer"],"created_at":"2025-11-13T09:00:33.298Z","updated_at":"2025-11-15T10:01:12.454Z","avatar_url":"https://github.com/D2KLab.png","language":"JavaScript","readme":"SPARQL Transformer\n===================\n\nWrite your SPARQL query directly in the JSON-LD you would like to have in output.\n\nJavaScript package. Try it with the [Playground](https://d2klab.github.io/sparql-transformer/).\n\n\u003e Looking for the [Python one](https://github.com/D2KLab/py-sparql-transformer)?\n\n## News\n\n- The parameter `$libraryMode` allows to perform the pagination on the merged objects, obtaining exactly `n=$limit` objects\n- It is now possible to set a different **merging anchor** instead of `id`/`@id` using the `$anchor` modifier.\n\n**Table of Contents**\n\n- [Motivation](./motivation.md)\n- [Query in JSON](#query-in-json)\n- [How to use](#how-to-use)\n- [Credits](#credits)\n\nYou want to learn more? Watch this [Tutorial](https://d2klab.github.io/swapi2020/slides.html)\n\n## Query in JSON\n\nThe core idea of this module is writing in a single file the query and the expected output in JSON.\n\nTwo syntaxes are supported: plain JSON and JSON-LD.\nHere the examples in the 2 formats for the query of cities.\n\n- plain JSON\n\n```json\n{\n  \"proto\": [{\n    \"id\" : \"?id\",\n    \"name\": \"$rdfs:label$required\",\n    \"image\": \"$foaf:depiction$required\"\n  }],\n  \"$where\": [\n    \"?id a dbo:City\",\n    \"?id dbo:country dbr:Italy\"\n  ],\n  \"$limit\": 100\n}\n```\n\n- JSON-LD\n\n```json\n{\n  \"@context\": \"http://schema.org/\",\n  \"@graph\": [{\n    \"@type\": \"City\",\n    \"@id\" : \"?id\",\n    \"name\": \"$rdfs:label$required\",\n    \"image\": \"$foaf:depiction$required\"\n  }],\n  \"$where\": [\n    \"?id a dbo:City\",\n    \"?id dbo:country dbr:Italy\"\n  ],\n  \"$limit\": 100\n}\n```\n\nThe syntax is composed by two main parts.\n\n### The prototype\n\nThe `@graph`/`proto` property contains the prototype of the result as I expect it. When the value should be taken from the query result, I declare it using the following syntax:\n\n    $\u003cSPARQL PREDICATE\u003e[$modifier[:option...]...]\n\nThe subject of the predicate is the variable (declared of automatically assigned) of the closer **mergin anchor** in the structure, which is the `@id`/`id` property (if it exists, otherwise is the default `?id`).\nThe SPARQL variable name is manually (with the `$var` modifier) or automatically assigned.\n\nSome modifiers can be present after, separated by the `$` sign. The `:` prepend the options for a given modifier.\n\n|MODIFIER|OPTIONS|NOTE|\n|---|---|---|\n|`$required`|n/a| When omitted, the clause is wrapped by `OPTIONAL { ... }`.|\n|`$sample`|n/a|Extract a single value for that property by adding a `SAMPLE(?v)` in the SELECT|\n|`$lang`|`:lang`[string, optional]| FILTER by language. In absence of a language, pick the first value of `$lang` in the root.\u003cbr\u003eEx. `$lang:it`, `$lang:en`, `$lang`. |\n|`$bestlang`|`:acceptedLangs`[string, optional]| Choose the best match (using `BEST_LANGMATCH`) over the languages according to the list expressed through the [Accept-Language standard](https://tools.ietf.org/html/rfc7231#section-5.3.5). This list can be appended after the `:` or expressed as `$lang` in the root.\u003cbr\u003eEx. `$bestlang`, `$bestlang:en;q=1, it;q=0.7 *;q=0.1`|\n|`$var`|`:var`[string]| Specify the variable that will be assigned in the query, so that it can be referred in the root properties (like `$filter`). If missing, a `?` is prepended. \u003cbr\u003e Ex. `$var:myVariable`, `$var:?name`|\n|`$anchor`|n/a|Set this property as merging anchor. The set is valid for the current level in the JSON tree, ignoring eventual `id`/`@id` sibling properties. Ex. `\"a\":\"?example$anchor\"` sets`?example` as subject of SPARQL statements and merges the final results on the `a` property.|\n|`$reverse`|n/a|Set this property for use the current variable as subject of the SPARQL predicate, rather than object.|\n|`$count` `$sum` `$min` `$max` `$avg`| n/a | Return the respective aggregate function (COUNT, SUM, MIN, MAX, AVG) on the variable. |\n|`$langTag`|`\"hide\"`, `\"show\"` (default)| When `hide`, language tags are not included in the output.\u003cbr\u003e Ex. `hide` =\u003e `\"label\":\"Bologna\"` ;\u003cbr\u003e  `show` =\u003e `\"label\":{\"value\": \"Bologna\", \"language\": \"it\"}` |\n|`$accept`|`\"string\"`, `\"number\"`, `\"boolean\"`| If set, values of type different from the specified one are discarded. |\n|`$alist`|n/a| When set, the interested property value would always be a list, even if with a single element.|\n\nIn this way, I specify a mapping between the JSON-LD output properties and the ones in the endpoint. The values non prepended by a `$` are transferred as is to the output.\n\n### The root `$` properties\n\nThe `$`-something root properties allow to make the query more specific. They will be not present in the output, being used only at query level.\nThe supported properties are:\n\n|PROPERTY|INPUT|NOTE|\n|--------|-----|----|\n|`$where`|string, array| Add where clause in the triple format.\u003cbr\u003eEx. `\"$where\": \"?id a dbo:City\"`|\n|`$values`|object| Set `VALUES` for specified variables as a map. The presence of a lang tag or of the '$lang' attribute attached to the related property is taken in account. \u003cbr\u003eEx. `\"$values\": {\"?id\": [\"dbr:Bari\", \"http://dbpedia.org/resource/Bologna\"]}`|\n|`$limit` |number| `LIMIT` the SPARQL results |\n|`$limitMode` |`query` (default) or `library`| Perform the LIMIT operation in the query or on the obtained results (`library`) |\n|`$from` |string(uri)| Define the graph `FROM` which selecting the results |\n|`$offset` |number| `OFFSET` applied to the SPARQL results |\n|`$distinct`|boolean (default `true`)| Set the `DISTINCT` in the select|\n|`$orderby`|string, array| Build an `ORDER BY` on the variables in the input.\u003cbr\u003e Ex. `\"$orderby\":[\"DESC(?name)\",\"?age\"]`|\n|`$groupby`| string, array | Build an `GROUP BY` on the variables in the input. \u003cbr\u003e Ex. `\"$groupby\":\"?id\"`|\n|`$having`| string, array | Allows to declare the content of `HAVING`. If it is an array, the items are concatenated by `\u0026\u0026`. |\n|`$filter`| string, array |Add the content as a `FILTER`.\u003cbr\u003e`\"$filter\": \"?myNum \u003e 3\"`|\n|`$prefixes`| object | set the prefixes in the format `\"foaf\": \"http://xmlns.com/foaf/0.1/\"`.|\n|`$lang`|`:acceptedLangs`[string]| The default language to use as `$bestlang` (see above), expressed through the [Accept-Language standard](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4). \u003cbr\u003eEx. `$lang:en;q=1, it;q=0.7 *;q=0.1`|\n|`$langTag`|`\"hide\"`, `\"show\"` (default)| When `hide`, language tags are not included in the output. Similar to the inline `$langTag`, but acting at a global level.\u003cbr\u003e Ex. `hide` =\u003e `\"label\":\"Bologna\"` ;\u003cbr\u003e  `show` =\u003e `\"label\":{\"value\": \"Bologna\", \"language\": \"it\"}` |\n\nThe `@context` property (for the JSON-LD version) will be transferred to the output.\n\nThe output of this query is intended to be:\n- for the plain JSON, an array of object with the shape of the prototype;\n- for the JSON-LD, an array of object with the shape of the prototype in the `@graph` property and with a sibling `@context`.\n\n## How to use\n\n#### Install in nodeJS\nInstall by npm.\n\n```bash\nnpm install sparql-transformer\n```\n\n\nAdd to the application.\n\n```js\nimport sparqlTransformer from 'sparql-transformer';\n```\n\n#### Install in the browser\n\nSPARQL Transformer is exposed as [ES Module](https://jakearchibald.com/2017/es-modules-in-browsers/). We rely on [getlibs](https://www.npmjs.com/package/getlibs) until the technology will allow to use [\"bare\" import specifier](https://github.com/WICG/import-maps#bare-specifiers).\n\n```html\n\u003cscript src=\"https://unpkg.com/getlibs\"\u003e\u003c/script\u003e\n\u003cscript\u003esparqlTransformer = System.import('https://unpkg.com/sparql-transformer')\u003c/script\u003e\n```\n\n#### Use\n```js\nsparqlTransformer(query, options)\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.error(err););\n\n```\n\nThe first parameter (`query`) is the query in the JSON-LD format. The JSON-LD can be:\n- an already parsed JS object (or defined real time),\n- **ONLY if running in NodeJS**, the local path of a JSON file (that will then be read and parsed).\n\nThe `options` parameter is optional, and can define the following:\n\n| OPTION | DEFAULT | NOTE |\n| --- | --- | --- |\n|context | http://schema.org/ | The value in `@context`. It overwrites the one in the query.|\n| sparqlFunction | `null` | A function receiving in input the transformed query in SPARQL, returning a Promise. If not specified, the module performs the query on its own\u003csup id=\"a1\"\u003e[1](#f1)\u003c/sup\u003e against the specified endpoint.  |\n| endpoint | http://dbpedia.org/sparql | Used only if `sparqlFunction` is not specified. |\n| debug | `false` | Enter in debug mode. This allow to print in console the generated SPARQL query. |\n| params | `{}` | Additional parameters to pass to the HTTP query |\n\n\nSee [`test.js`](./test.js) for further examples.\n\n\n## Credits\n\nIf you use this module for your research work, please cite:\n\n\u003e Pasquale Lisena, Albert Meroño-Peñuela, Tobias Kuhn and Raphaël Troncy. Easy Web API Development with SPARQL Transformer. In 18th International Semantic Web Conference (ISWC), Auckland, New Zealand, October 26-30, 2019.\n\n[BIB file](./bib/lisena2019easyweb.bib)\n\n\n\u003e Pasquale Lisena and Raphaël Troncy. Transforming the JSON Output of SPARQL Queries for Linked Data Clients. In WWW'18 Companion: The 2018 Web Conference Companion, April 23–27, 2018, Lyon, France.\nhttps://doi.org/10.1145/3184558.3188739\n\n[BIB file](./bib/lisena2018sparqltransformer.bib)\n\n---\n\n\u003cb id=\"f1\"\u003e1\u003c/b\u003e: Using a [lightweight SPARQL client](./src/sparql-client.mjs).\n","funding_links":[],"categories":["SPARQL","Benchmarks"],"sub_categories":["SPARQL Applications"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FD2KLab%2Fsparql-transformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FD2KLab%2Fsparql-transformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FD2KLab%2Fsparql-transformer/lists"}