Json Api Serializer icon

Json Api Serializer

Serialize data to Json Api Specification

Json Api Serializer

AI-generated

Summary

Serialize input data into a JSON API-compliant response, supporting single resource objects or arrays of resources, including optional related resources with one-to-one or one-to-many relationships, alongside optional pagination for resource arrays.

Inputs

  • response_type (required) — Choose whether to serialize a single resource object or an array of resources.
  • resource_type (required) — Set the type field for the primary resource(s).
  • resource_id (required) — Set the ID for the primary resource object(s), defaults to the input JSON's id as string.
  • resource_attributes (required) — Provide the attributes for the resource in JSON format; must be valid JSON.
  • included — Optionally add multiple related resources with specified type, relationship name, relationship type (one-to-one or one-to-many), attributes or attribute keys, and source arrays for one-to-many relationships, to include in the serialized response.
  • enable_include_resources — Set to true to enable including related resources with relationships in the response.
  • include_filter — Comma-separated list of relationship names to include in the response. If empty, no relationships are included. Defaults to the 'include' query parameter of the incoming request.
  • add_pagination — For array responses, set to true to add JSON API pagination links and meta data to the response.
  • pagination_base_url — The base URL to use for pagination links. Required if pagination is enabled.
  • pagination_page — The current page number for pagination. Required if pagination is enabled.
  • pagination_per_page — Number of items per page for pagination. Required if pagination is enabled.
  • pagination_total_count — Total number of resources across all pages. Required if pagination is enabled.
  • pagination_query_params — Additional query parameters to include in pagination links as a JSON object.

Output shape

a single JSON object representing the serialized JSON API response

The output JSON fully conforms to the JSON API specification. It includes a 'data' field holding either a single resource object or an array of resource objects, each with 'id', 'type', 'attributes', and optionally 'relationships' if related resources are included. When relationships are included, an 'included' array contains the related resource objects. Relationships support one-to-one and one-to-many types. For array responses with pagination enabled, 'links' and 'meta' fields provide pagination URLs and metadata, respectively. The output is returned as an array with one JSON object item.

Examples

Example 1: Serialize a single resource object with attributes and included related resources

Set 'Response' to 'Resource Object', specify 'Type', 'ID', and 'Attributes' of the resource, enable relationship includes, and add related resources under 'Include Resources' with appropriate relationship types. The node outputs a JSON API object with 'data' (resource with relationships) and 'included' (related resources).

Example 2: Serialize an array of resources from multiple input items with optional pagination and relationships

Set 'Response' to 'Resources Array', provide attributes for each input item, optionally enable relationship includes and/or pagination. Each item is serialized as a JSON API resource in the 'data' array, including included related resources if enabled. Pagination adds 'links' and 'meta' objects for page navigation.

Links

Discussion