Skip to content

TypeScript API / laikacms/json-api / fromJsonApi

Function: fromJsonApi() ​

ts
function fromJsonApi<T, I, O>(
   data, 
   _type, 
   idField
): O;

Transforms a JSON:API resource back to domain object format.

Injects type from the resource envelope (it was stripped from attributes by toJsonApi to comply with JSON:API §7.2.2) and merges the id back under the caller-supplied idField.

Type Parameters ​

Type Parameter
T extends string
I extends string
O extends Record<string, unknown>

Parameters ​

ParameterTypeDescription
data{ attributes: Omit<O, I | "type" | "id">; id: string; type: T; }The JSON:API resource
data.attributesOmit<O, I | "type" | "id">-
data.idstring-
data.typeT-
_typeTJSON:API resource type (for type checking, not used at runtime)
idFieldIName of the ID field in the domain object

Returns ​

O

Released under the MIT License.