Skip to content

NagaiKoki/json-api-typescript-deserializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deserialize JSON:API Type

  • deserialize JSON:API TypeScript

Usage

// Serialized JSON:API Type
type RelationShipsApiType = {
  data: {
    id: string;
    type: "user";
    attributes: {
      name: string;
    };
    relationships: {
      drinks: {
        data: {
          id: string;
          type: "drink";
        }[];
      };
      books: {
        data: {
          id: string;
          type: "book";
        }[];
      };
    };
    included:
      | {
          id: string;
          type: "drink";
          attributes: {
            name: string;
            image_url: string;
            created_at: string;
          };
        }[]
      | {
          id: string;
          type: "book";
          attributes: {
            title: string;
            image_url: string;
            published_at: string;
          };
        }[];
  };
};

type SampleRelationalJsonApiType =
  JsonApiRelationshipDeserializedType<RelationShipsApiType>;

// Deserialized JSON:API Type
const Sample3: SampleRelationalJsonApiType = {
  id: '1',
  name: "Nagai Koki",
  drinks: [
    {
      id: '1',
      name: "Coke",
      imageUrl: "https://avatars.githubusercontent.com/u/50698194?v=4",
      createdAt: "2021/01/01",
    },
  ],
  books: [
    {
      id: '1',
      title: "TDD",
      imageUrl: "https://avatars.githubusercontent.com/u/50698194?v=4",
      publishedAt: "2021/01/01",
    },
    {
      id: '2',
      title: "DDD",
      imageUrl: "https://avatars.githubusercontent.com/u/50698194?v=4",
      publishedAt: "2021/01/02",
    },
  ],
};

About

Deserialize JSON:API type

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published