JSON:API TypeScript Types

0.1.3 · abandoned · verified Sun Apr 19

This package provides TypeScript type definitions for JSON:API documents, enabling compile-time validation of JSON:API structures within TypeScript projects. The current stable version is 0.1.3, released in April 2019. Given the lack of updates since then, its release cadence is effectively inactive, and it should be considered abandoned. Its primary differentiator is its sole focus on providing type-checking for JSON:API, without including any runtime parsing or serialization logic. This makes it a lightweight option for projects that already handle data fetching and serialization and only require type-safety enforcement against the JSON:API specification.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the type definitions and validating a basic JSON:API document structure at compile-time.

import * as JSONAPI from 'jsonapi-typescript';

// ✅ This should be OK (a valid single-resource JSON:API document)
let validDoc: JSONAPI.Document = {
  data: {
    type: 'articles',
    id: '1',
    attributes: {
      title: 'Hello World'
    },
    relationships: {
      author: {
        data: { type: 'people', id: '9' }
      }
    }
  }
};

// ⛔️ This should NOT be OK (missing 'data' or 'errors' top-level keys, 'result' is invalid)
// let invalidDoc1: JSONAPI.Document = {
//   result: "Success!"
// };

// ⛔️ This should NOT be OK (empty Array is not a valid JSON:API document root)
// let invalidDoc2: JSONAPI.Document = [];

console.log('Valid JSON:API document example:', JSON.stringify(validDoc, null, 2));

view raw JSON →