# jsonld2graphobject

> Converts JSON-LD to an Object Literal Graph

Latest version **0.0.5** (published 2022-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsonld2graphobject
pnpm add jsonld2graphobject
yarn add jsonld2graphobject
bun add jsonld2graphobject
```

## 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.0.5 |
| Published | 2022-02-18 |
| First published | 2021-12-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 254.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jackson Morgan |
| Maintainers | jaxoncreed |

## Links

- npm: https://www.npmjs.com/package/jsonld2graphobject
- Repository: https://github.com/o-development/jsonld2graphobject
- Homepage: https://github.com/o-development/jsonld2graphobject#readme
- Issues: https://github.com/o-development/jsonld2graphobject/issues
- npm.io page: https://npm.io/package/jsonld2graphobject

## Dependencies (4)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [@rdfjs/types](https://npm.io/package/@rdfjs/types.md) ^1.0.1
- [@types/jsonld](https://npm.io/package/@types/jsonld.md) ^1.5.6
- [jsonld-context-parser](https://npm.io/package/jsonld-context-parser.md) ^2.1.5

## Recent versions

- 0.0.5 (latest) — 2022-02-18
- 0.0.4 — 2022-01-23
- 0.0.3 — 2021-12-29
- 0.0.2 — 2021-12-05
- 0.0.1 — 2021-12-05
- 0.0.0 — 2021-12-05

## README

> :warning: **This repository is archived**: It's contents have been moved to a new [monorepo](https://github.com/o-development/ldo/).

# JSON 2 Graph Object

JSON-LD makes working with RDF easier, but it forces data into a tree structure. JSON 2 Graph Object makes a true graph from Object literals.

## Purpose
JSON-LD is great for making RDF easy for JavaScript developers, but it's not perfect.

```json
{
  "@context": {
    "friend": { "@type": "@id" }
  },
  "@id": "http://example.com/friend1",
  "friend": {
    "@id": "http://example.com/friend2",
    "friend": "http://example.com/friend1"
  }
}
```

The above example is not a true graph, as the `friend` field in `friend2` is simply the id of the friend, not the friend itself.

## Intallation

```bash
npm i jsonld2graphobject
```

## Usage

Provide any compliant JSON-LD document as well as the id for the return node.

```javascript
import { jsonld2graphobject } from "jsonld2graphobject";

async function run() {
  const friend1 = await jsonld2graphobject(
    {
      "@context": {
        "friend": { "@type": "@id" }
      },
      "@id": "http://example.com/friend1",
      "friend": {
        "@id": "http://example.com/friend2",
        "friend": "http://example.com/friend1"
      }
    },
    "http://example.com/friend1",
    { excludeContext: false } // excludeContext defaults to false
  );
  // Prints friend 1
  console.log(friend1.friend.friend.friend.friend.friend.friend.friend.friend.friend.friend);
}
run();
```

## Known Limitations
 - This library doesn't consider named graphs

---
_Source: https://npm.io/package/jsonld2graphobject · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
