# @graviola/json-schema-graph-extract

> SPARQL Query generator: @graviola/json-schema-graph-extract

Latest version **0.1.1** (published 2023-06-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @graviola/json-schema-graph-extract
pnpm add @graviola/json-schema-graph-extract
yarn add @graviola/json-schema-graph-extract
bun add @graviola/json-schema-graph-extract
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-06-28 |
| First published | 2023-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 175.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | graviola |

## Links

- npm: https://www.npmjs.com/package/@graviola/json-schema-graph-extract
- npm.io page: https://npm.io/package/@graviola/json-schema-graph-extract

## Dependencies (4)

- [clownface](https://npm.io/package/clownface.md) ^1.5.1
- [@rdfjs/namespace](https://npm.io/package/@rdfjs/namespace.md) ^2.0.0
- [@rdfjs/data-model](https://npm.io/package/@rdfjs/data-model.md) ^2.0.1
- [@graviola/json-schema-core](https://npm.io/package/@graviola/json-schema-core.md) 0.1.2

## Recent versions

- 0.1.1 (latest) — 2023-06-28
- 0.1.0 — 2023-06-28

## README

<h1 align="center"> SPARQL Query generator: @graviola/json-schema-graph-extract </h1>
<p>
  <img alt="Version" src="https://img.shields.io/badge/version-0.1.1-blue.svg?cacheSeconds=2592000" />
  <img src="https://img.shields.io/badge/node-%3E%3D10-blue.svg" />
  <a href="https://gravio-la.github.io/json-schema-graph-extract" target="_blank">
    <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
  </a>
  <a href="#" target="_blank">
    <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
  </a>
</p>

A library to get JSON documents using JSON-Schema out of a knowledge graph

### 🏠 [Homepage](https://gravio-la.github.io/json-schema-graph-extract)

## Prerequisites

- node >=10

## Install

```sh
yarn add @graviola/json-schema-graph-extract
```

### Usage

given the following json schema
```json
{
  "$defs": {
    "Address": {
      "type": "object",
      "properties": {
        "addressCountry": {
          "type": "string"
        },
        "addressRegion": {
          "type": "string"
        },
        "postalCode": {
          "type": "string"
        },
        "streetAddress": {
          "type": "string"
        },
      }
    },
    "Person": {
      "title": "Person",
      "description": "A human being",
      "type": "object",
      "properties": {
        "familyName": {
          "type": "string"
        },
        "givenName": {
          "type": "string"
        },
        "address": {
          "$ref": "#/$defs/Address"
        }
      }
    }
  },
  "$schema": "http://json-schema.org/draft-06/schema#",
  "$id": "https://example.com/person.schema.json",
}
```

and a knowledge graph that contains the following triples:

```turtle
@prefix : <https://example.com/person.schema.json#> .
@prefix ex: <http://example.com/entities#> .

ex:me a :Person ;
  :familyName "Meneman" ;
  :givenName "Max" ;
  :address ex:address .
    :addressCountry "Germany" ;
    :addressRegion "Berlin" ;
    :postalCode "10967" ;
    :streetAddress "Humboldforum 7821" .
```

call the `extractDocumentFromDataset` function with on any dataset:

```javascript
    const baseIRI = 'http://example.com',
          entityIRI = 'http://example.com/entities#me'
    const data = extractDocumentFromDataset(
      baseIRI, 
      entityIRI, 
      dataset, 
      schema, 
      { 
        omitEmptyArrays: true,
        omitEmptyObjects: true,
        maxRecursionEachRef: 1,
        maxRecursion: 5 
      })
```

the result data serialized to json will look like this:

```json
{
  "@id": "http://example.com/entities#me",
  "@type": "Person",
  "familyName": "Meneman",
  "givenName": "Max",
  "address": {
    "addressCountry": "Germany",
    "addressRegion": "Berlin",
    "postalCode": "10967",
    "streetAddress": "Humboldforum 7821"
  }
}
```

if the entry exists within the dataset and the document is valid according to the schema.

In the example the `maxRecursionEachRef` and `maxRecursion` options are used to limit the depth of the recursion.
It is possible to have a schema that references itself, which would lead to an infinite recursion.

In future versions a more fine grained control over the recursion will be possible.

The `omitEmptyArrays` and `omitEmptyObjects` options are used to omit empty arrays and objects from the result.

## Author

👤 **Sebastian Tilsch**

* Github: [@bastiion](https://github.com/bastiion)

## Show your support

Give a ⭐️ if this project helped you!

---
_Source: https://npm.io/package/@graviola/json-schema-graph-extract · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
