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

getj

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

getj

get json

latest
Source
npmnpm
Version
0.0.12
Version published
Maintainers
1
Created
Source

npm version

getj

getj(uri: string): Promise<Object>

The getj function is an asynchronous function that retrieves JSON-LD or JSON data from a given URI.

Parameters

  • uri (string): The URI from which to fetch the JSON-LD or JSON data.

Returns

  • A Promise that resolves to the JSON-LD or JSON object found in the fetched document.

Usage

import getj from 'getj'

getj('https://example.com')
  .then(json => {
    console.log(json)
  })
  .catch(error => {
    console.error('Error:', error)
  })

Demo

Try the demo

Description

The getj function takes a URI as input and performs the following steps:

  • Fetches the document at the given URI.
  • Parses the fetched document into a DOM structure.
  • Searches for a <script> element with a type attribute of "application/ld+json" or "application/json".
  • If found, parses the content of the <script> element into a JSON object.
  • If a fragment identifier is present in the input URI, searches for a nested object with a matching ID or '@id' property within the JSON object.
  • Returns the matching nested object if found, or the entire JSON object if no fragment identifier is present or no matching object is found.

FAQs

Package last updated on 24 Apr 2023

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