Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonld

Package Overview
Dependencies
Maintainers
2
Versions
214
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonld

A JSON-LD Processor and API implementation in JavaScript.

  • 0.0.21
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
131K
increased by13.48%
Maintainers
2
Weekly downloads
 
Created

What is jsonld?

The jsonld package is a JavaScript library for working with JSON-LD, a JSON-based format for representing linked data. It provides tools for transforming JSON-LD documents, compacting, expanding, and framing data, and converting between JSON-LD and other RDF serializations.

What are jsonld's main functionalities?

Compacting

Compacting a JSON-LD document means transforming it into a more compact form using a context. This is useful for reducing the size of the data and making it easier to read.

const jsonld = require('jsonld');

const doc = {
  "@context": {
    "name": "http://schema.org/name",
    "homepage": {
      "@id": "http://schema.org/url",
      "@type": "@id"
    }
  },
  "name": "Manu Sporny",
  "homepage": "http://manu.sporny.org/"
};

const context = {
  "name": "http://schema.org/name",
  "url": "http://schema.org/url"
};

jsonld.compact(doc, context).then(compacted => {
  console.log(JSON.stringify(compacted, null, 2));
});

Expanding

Expanding a JSON-LD document means transforming it into a fully expanded form where all terms are expressed in their full IRI form. This is useful for processing data in a more uniform way.

const jsonld = require('jsonld');

const doc = {
  "@context": {
    "name": "http://schema.org/name",
    "homepage": {
      "@id": "http://schema.org/url",
      "@type": "@id"
    }
  },
  "name": "Manu Sporny",
  "homepage": "http://manu.sporny.org/"
};

jsonld.expand(doc).then(expanded => {
  console.log(JSON.stringify(expanded, null, 2));
});

Framing

Framing a JSON-LD document allows you to extract a specific subgraph of the data, organized according to a frame. This is useful for extracting and presenting data in a specific structure.

const jsonld = require('jsonld');

const doc = {
  "@context": {
    "name": "http://schema.org/name",
    "homepage": {
      "@id": "http://schema.org/url",
      "@type": "@id"
    }
  },
  "@graph": [
    {
      "@id": "_:b0",
      "name": "Manu Sporny",
      "homepage": "http://manu.sporny.org/"
    }
  ]
};

const frame = {
  "@context": {
    "name": "http://schema.org/name",
    "homepage": {
      "@id": "http://schema.org/url",
      "@type": "@id"
    }
  },
  "@type": "http://schema.org/Person"
};

jsonld.frame(doc, frame).then(framed => {
  console.log(JSON.stringify(framed, null, 2));
});

Other packages similar to jsonld

Keywords

FAQs

Package last updated on 21 Feb 2013

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc