New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jsonld2graphobject

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonld2graphobject

Converts JSON-LD to an Object Literal Graph

latest
Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
1.8K
4.83%
Maintainers
1
Weekly downloads
 
Created
Source

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.

{
  "@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

npm i jsonld2graphobject

Usage

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

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

FAQs

Package last updated on 18 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts