json-api-serializer is a versatile JavaScript library for Node.js and browsers, designed to serialize JavaScript objects into JSON:API 1.0 compliant documents and deserialize JSON:API documents back into standard JavaScript objects. The current stable version is 2.6.6. It maintains an active development cycle, frequently releasing minor updates and bug fixes. Key differentiators include its framework-agnostic nature, extensive configuration options for defining complex relationships, links, and metadata, and support for both serialization and deserialization processes. It allows for fine-grained control over attribute whitelisting/blacklisting, case conversion, and custom logic for handling relationships, making it adaptable to various JSON:API implementations.
npm install json-api-serializerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `json-api-serializer`, register custom schemas for 'user' and 'post' types with relationships, and then perform both serialization of a JavaScript object into JSON:API format and deserialization of a JSON:API document back into a plain object. It highlights `id` customization, blacklisting attributes, and defining relationship logic.
Upgrade to `json-api-serializer` version 2.4.1 or higher. Ensure your data structures are not unintentionally circular, especially when defining `relationships` where an object might reference itself or an ancestor.
Always ensure all related `type`s specified in `relationships` options are registered before performing serialization or deserialization operations. For example, if a 'user' has 'posts', both 'user' and 'post' types must be registered.
Upgrade to version `2.6.6` or higher to correctly handle cases where `id` might be missing in the input. Alternatively, implement defensive checks in your application code for `id` presence after deserialization.
This was a fix in `v2.6.4`. Be aware that if your application relied on the presence of an `included` array in older versions even when no relationships had attributes, you might need to adjust your expectations or post-processing logic when upgrading.
Refactor your data to break circular dependencies, or ensure you are using `json-api-serializer` version 2.4.1 or higher which includes fixes for preventing circular deserialization.
Register all resource types involved in relationships using `serializer.register('type', options)` before performing any serialization or deserialization operations that involve those relationships.Ensure all relationships are properly registered. Review the `deserialize` function for relationships in your `serializer.register()` options to handle cases where `data` might be `null` or `undefined`, especially for optional relationships. Upgrade to `v2.6.5` or higher which fixes errors when deserializing unregistered relationships.
No dependency data recorded yet.