JSON API Normalizer

1.0.4 · abandoned · verified Sun Apr 19

The `json-api-normalizer` package provides a utility to transform JSON:API compliant response data into a normalized, Redux-friendly format. Unlike general-purpose normalization libraries such as Normalizr, this package directly interprets the JSON:API specification, eliminating the need for manual schema definitions. It converts collections of resources into key-value maps, where keys are resource IDs, making it highly suitable for efficient state management within Redux applications. The current stable version is 1.0.4. Development appears to be largely inactive since 2017, with the last commit on GitHub approximately five years ago, suggesting a potentially abandoned status. Its primary differentiator is its direct, schema-less adherence to the JSON:API specification, providing a simpler setup for compliant APIs.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to normalize a JSON:API response, including related 'included' data, and how to use the `endpoint` option to store request-specific metadata.

import normalize from 'json-api-normalizer';

const json = {
  data: [{
    "type": "post-block",
    "relationships": {
      "question": {
        "data": {
          "type": "question",
          "id": "295"
        }
      }
    },
    "id": "2620",
    "attributes": {
      "text": "I am great!",
      "id": 2620
    }
  }],
  included: [{
    "type": "question",
    "id": "295",
    "attributes": {
      "text": "How are you?",
      id: 295
    }
  }]
};

console.log(normalize(json));
/* Expected Output:
{
  question: {
    "295": {
      id: 295,
      type: "question"
      attributes: {
        text: "How are you?"
      }
    }
  },
  postBlock: {
    "2620": {
      id: 2620,
      type: "postBlock",
      attributes: {
        text: "I am great!"
      },
      relationships: {
        question: {
          type: "question",
          id: "295"
        }
      }
    }
  }
}
*/

const normalizedWithEndpoint = normalize(json, { endpoint: '/post-block/2620' });
console.log(normalizedWithEndpoint.meta);

view raw JSON →