npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jsonapiclient

v0.2.0

Published

Easily traverse and manipulate JSON API data

Downloads

10

Readme

jsonapiclient

JSON API is a nice standard that solves a lot of bikeshedding problems when designing HTTP-based APIs. However, due to its non-flat payloads, reading and manipulating JSON API structures can result in a good deal of boilerplate code. To that end, this library aims to capture the boilerplate code and make it easier to work with JSON API data.

The library exposes two concepts: Resources and Collections.

Resources

A Resource instance corresponds to a JSON API payload where data is a single item like the one found here

You can initialize a Resource instance from existing data like so:

const resource = Resource.fromObject(JSON.parse(payload));

You can also create a new Resource instance like so:

const resource = Resource.create('people', 'a1a51071-8266-40e8-8fca-bc293db66ef9');

One you have a resource instance, you have access to several methods for access and manipulating the payload's fields.

// set an attribute field
resource.set(['size', 'width'], '1080')    

// get an attribute field
resource.get(['title'])  // => 'Uluru'
resource.get(['size', 'width']) // => '1080'

// remove an attribute field
resource.unset(['size'])

// Replace payload attributes.
// TIP: This is a good way to populate an empty resource
resource.replace({
  title: 'Good Morning, Uluru',
  src: 'http://example.com/images/morning.png'
})

The full list of Resource methods is documented in the API section below.

Traversing relationships

Resources often carry information about related resources as seen in the example above. These can be easily accessed as Resource instances themselves:

const related = resource.relationship('photographer')
console.log(JSON.stringify(related.serialize(), null, 2))
// =>
// {
//   "data": {
//     "id": "ff4860a8-2b5f-4c35-9e03-27c872ff9056",
//     "type": "people"
//   }
// }

// If there are included resources in the payload, you can resolve the relationship
const resolved = resource.relationship('photographer', {resolve: true});
console.log(JSON.stringify(related.serialize(), null, 2))
// =>
// {
//   "data": {
//     "type": "people",
//     "id": "ff4860a8-2b5f-4c35-9e03-27c872ff9056",
//     "attributes": {
//       "firstName": "George",
//       "lastName": "Haidar",
//       "twitter": "ghaidar0"
//     },
//     "links": {
//       "self": "http://example.com/people/ff4860a8-2b5f-4c35-9e03-27c872ff9056"
//      }
//   }
// }

Collections

A Collection instance corresponds to a JSON API payload where data is an array of items like the one found here

You can initialize a Collection instance from existing data like so:

const collection = Collection.fromObject(JSON.parse(payload));

You can also create a new Collection instance like so:

const collection = Collection.create();

Once you have a collection instance, you can access its list of items which are presented as Resource instances:

collection.at(0).get('title') // => 'JSON API paints my bikeshed!'

There are also several methods available to manipulate the collection:

// add an item to the end
collection.push({
  type: 'article',
  id: '12',
  attributes: {
    title: 'Hello, World!'
  }
});

The full list of Collection methods is documented in the API section below.

API