codable

Guides Swift 6.x Codable conformance for JSON and PropertyList encoding and decoding.

1.1k|81|Updated Nov 30, 2025
One-click install
npx skills add https://github.com/CharlesWiltgen/Axiom --skill codable
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: codable
Source: https://github.com/CharlesWiltgen/Axiom/tree/main/.claude-plugin/plugins/axiom/skills/codable
Command: npx skills add https://github.com/CharlesWiltgen/Axiom --skill codable

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Comprehensive patterns for Codable conformance: JSON and PropertyList encoding/decoding, CodingKeys customization, enum encoding, and dealing with common Decodable/Encodable errors in Swift 6.x.

Core Features & Use Cases

  • Automatic synthesis for Codable conformance
  • CodingKeys customization to rename or exclude keys
  • Enum encoding patterns and associated values
  • Debugging common decoding/encoding errors

Quick Start

Decode a JSON payload into a Swift struct using automatic synthesis and CodingKeys.

Frequently Asked Questions about codable

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

FAQPage Schema
How do I make a Swift struct automatically conform to Codable for JSON encoding and decoding?

Swift automatically synthesizes Codable conformance when all properties in a struct conform to Codable. Simply declare the struct as `Codable` and the compiler generates init(from:) and encode(to:) methods without additional code, supporting JSON and PropertyList formats.

When do I need to use CodingKeys to customize JSON field names in Swift?

CodingKeys customization is needed when JSON field names don't match Swift property names or you want to exclude properties from encoding/decoding. Define a CodingKeys enum inside your type listing each property with its corresponding JSON key string.

How do I manually implement Codable for enums with associated values in Swift?

Manually implement init(from:) and encode(to:) using keyed containers to encode the enum case and its associated values separately. For raw-value enums, automatic synthesis works if all raw values conform to Codable; associated-value enums require custom implementations.

What causes common Codable decoding errors and how do I fix them?

Common errors include type mismatches, missing keys, and unexpected null values. Debug by checking JSON structure matches property types, verify CodingKeys spelling, use dateDecodingStrategy for date fields, and handle optional properties or provide default values for missing keys.

Can I use Codable with Swift PropertyList encoding in addition to JSON?

Yes. Any type conforming to Codable works with both JSONEncoder/JSONDecoder and PropertyListEncoder/PropertyListDecoder. The same Codable implementation handles both formats without modification; only the encoder/decoder type changes.

How do I handle date and custom type encoding in Codable implementations?

Set dateDecodingStrategy and dateEncodingStrategy on JSONEncoder/JSONDecoder to control date formatting. For custom types, implement Codable manually or use container methods to encode/decode nested structures as intermediate types then transform them.