{"id":27085,"library":"jsonapi-serializer","title":"jsonapi-serializer","description":"A Node.js framework-agnostic library for serializing and deserializing data to JSON API 1.0 compliant format. Current stable version is 3.6.9, maintained with infrequent releases (last in 2020). Differentiators include heavy customization options (custom attribute keys via keyForAttribute, transforms, top-level links, nested relationships) and support for both serialization and deserialization. Compared to alternatives like jsonapi-store-relationaldb or fast-jsonapi, it offers more fine-grained control over meta, links, and relationship configuration.","status":"maintenance","version":"3.6.9","language":"javascript","source_language":"en","source_url":"https://github.com/SeyZ/jsonapi-serializer","tags":["javascript"],"install":[{"cmd":"npm install jsonapi-serializer","lang":"bash","label":"npm"},{"cmd":"yarn add jsonapi-serializer","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsonapi-serializer","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import works in Node >=12 with type module; CommonJS require is supported for older Node versions.","wrong":"const Serializer = require('jsonapi-serializer').Serializer","symbol":"Serializer","correct":"import { Serializer } from 'jsonapi-serializer'"},{"note":"Same import pattern as Serializer.","wrong":"const Deserializer = require('jsonapi-serializer').Deserializer","symbol":"Deserializer","correct":"import { Deserializer } from 'jsonapi-serializer'"},{"note":"The Error class is a named export, not default.","wrong":"import Error from 'jsonapi-serializer'","symbol":"Error","correct":"import { Error } from 'jsonapi-serializer'"}],"quickstart":{"code":"import { Serializer } from 'jsonapi-serializer';\nconst serializer = new Serializer('articles', {\n  attributes: ['title', 'body', 'author'],\n  author: {\n    ref: 'id',\n    included: true,\n    attributes: ['firstName', 'lastName']\n  }\n});\nconst data = {\n  id: '1',\n  title: 'JSON API is awesome',\n  body: 'It works!',\n  author: {\n    id: '2',\n    firstName: 'Sandro',\n    lastName: 'Munda'\n  }\n};\nconst serialized = serializer.serialize(data);\nconsole.log(JSON.stringify(serialized, null, 2));","lang":"javascript","description":"Serializes an article object with included author relationship to JSON API format."},"warnings":[{"fix":"Update to v3 and ensure 'type' is a string and 'ref' inside relationships points to 'id' field.","message":"In v3, the 'type' field is mandatory and must be a string; v2 accepted objects. Also, 'id' parameter for relationships becomes required.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"Use 'keyForAttribute: 'dash-case'' instead of 'dasherize'.","message":"The 'keyForAttribute' option with value 'dasherize' (or 'dash-case') is deprecated in v3.6.0 in favor of direct string 'dash-case'.","severity":"deprecated","affected_versions":">=3.6.0"},{"fix":"Always define 'attributes' list to control output and avoid inclusion of unintended fields.","message":"If you omit 'attributes' array, the serializer will include all properties from the input data, including nested objects that might not be valid JSON API.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Explicitly set 'included: false' if you do not want full inclusion.","message":"In v3, the 'included' option defaults to true for relationships. If you set 'included: false', the relationship data will still be present under 'relationships' but not in 'included' top-level array.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Ensure your data structures are acyclic or use a custom transform to prune cycles.","message":"The library does not support circular references; it will throw a RangeError: Maximum call stack size exceeded.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"new Serializer('resourceType', opts)","cause":"Missing or invalid first argument to Serializer constructor.","error":"Error: The 'type' argument is required"},{"fix":"Pass a valid object or array to serializer.serialize(data).","cause":"Serializer called on undefined or null data, or 'data' field missing from input.","error":"TypeError: Cannot read property 'attributes' of undefined"},{"fix":"Ensure each resource object has an 'id' field, or adjust relationship 'ref' to another unique field.","cause":"Data object missing 'id' field while 'ref' is set in relationship options.","error":"Error: You must provide an 'id' for the resource"},{"fix":"Use import syntax instead: import { Serializer } from 'jsonapi-serializer'","cause":"Trying to use CommonJS require in an ES module context (e.g., type: module in package.json).","error":"ReferenceError: require is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}