Upon receiving a JSON response from the server, it typically looks something like this:
{
data: [
{ id: 1, type: 'person', emails: [ { id: 1 }, { id: 3 } ], phones: [] },
{ id: 2, type: 'person', emails: [ { id: 2 } ], phones: [ { id: 2 } ] },
{ id: 3, type: 'person', emails: [ { id: 4 } ], phones: [ { id: 3 }, { id: 3 }] }
],
included: [
{ id: 1, type: 'emails', ... },
{ id: 2, type: 'emails', ... },
{ id: 3, type: 'emails', ... },
{ id: 4, type: 'emails', ... },
{ id: 1, type: 'phones', ... },
{ id: 2, type: 'phones', ... },
{ id: 3, type: 'phones', ... }
]
}
The data
property consists of contact objects with similar structures, each having arrays of related emails and phones.
The included
property contains all types of related objects, which can share an ID or have different object structures.
The goal is to flatten the response for easier manipulation and achieve a structure like this:
{
entities: {
contacts: [ ... ],
emails: [ ... ],
phones: [ ... ]
},
result: [ 1, 2, 3 ]
}
Normalizing just the contact data using the provided method does not include emails or phones in the entities
.
If unsure if the library supports this specific transformation, reaching out for assistance may be beneficial.
Though the example above doesn't match the actual data, the API follows the schema outlined by jsonapi.org, aligning with its structure.