json-typed-attributes

Define typed JSON-backed attributes in Rails models with type casting and validations.

6|1|Updated Feb 4, 2026
One-click install
npx skills add https://github.com/RoleModel/rolemodel-skills --skill json-typed-attributes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: json-typed-attributes
Source: https://github.com/RoleModel/rolemodel-skills/tree/main/skills/json-typed-attributes
Command: npx skills add https://github.com/RoleModel/rolemodel-skills --skill json-typed-attributes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rails apps often need to store dynamic data without creating new columns. This skill provides typed JSON-backed attributes in Rails models via the StoreJsonAttributes concern, offering automatic type casting, validations, and seamless form integration.

Core Features & Use Cases

  • Define and cast typed attributes (string, integer, decimal, boolean, date, array, text) stored in a single JSON column.
  • Validate JSON-backed attributes like regular ActiveRecord attributes and integrate with Rails forms.
  • Use cases include storing configuration, metadata, or dynamic fields within a single jsonb column.

Quick Start

Create a Rails model with a JSONB column named data and include the StoreJsonAttributes concern. Then define typed attributes, e.g.:

  • store_typed_attributes [:timeline], type: :string, field: :data
  • store_typed_attributes [:categories], type: :array, field: :data You can add validations and strong parameters as needed.

Frequently Asked Questions about json-typed-attributes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I store typed attributes in a Rails JSONB column?

Store typed attributes in a Rails JSONB column by including the StoreJsonAttributes concern and defining fields with store_typed_attributes. This handles type casting for strings, integers, arrays, and booleans within a single JSON column.

Can I validate JSON-backed attributes in Rails models like regular columns?

Validating JSON-backed attributes works like regular ActiveRecord columns. The StoreJsonAttributes approach integrates seamlessly, allowing standard validations on dynamic fields stored in your JSONB data column.

What is the best way to handle dynamic settings and metadata in Rails without adding new database columns?

Handling dynamic settings without new columns involves using a JSONB field to store configurations. The StoreJsonAttributes concern enables accessing this metadata via typed attributes with automatic casting and form integration.

Does Rails form integration work with dynamic fields stored in JSONB?

Rails form integration works smoothly with JSONB fields. The StoreJsonAttributes concern exposes typed attributes that function like native columns, ensuring seamless binding with Rails forms and strong parameters.

What data types are supported when casting JSON attributes in Rails?

Casting JSON attributes supports string, integer, decimal, boolean, date, array, and text types. You define these types using store_typed_attributes to ensure proper data handling within your JSONB column.

Why use a concern for typed JSON attributes instead of Rails serialized columns?

Using a concern for typed JSON attributes provides explicit type casting, validations, and form integration for JSONB fields. This approach treats dynamic metadata as structured, validated attributes rather than simple serialized hashes.