swift-codable-json

swift-codable-json is a skill for Claude Code, Codex from dagba/ios-mcp. It costs 43 tokens per session (3,531 once invoked), scanned A, original, MIT.

A set of Swift patterns for converting JSON to and from typed Swift values with `Codable`. JSON is a common text format used by APIs to send structured data.

In plain words
What is it for?
Use it when building Swift API responses, mapping snake_case fields to camelCase, handling dates, or decoding inconsistent JSON.
Why use it?
It helps prevent decoding failures when API data has different names, date formats, missing fields, or nested structures.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/dagba/ios-mcp/swift-codable-json
Any agent
npx skills add dagba/ios-mcp --skill swift-codable-json
Clone the repo
git clone --depth 1 https://github.com/dagba/ios-mcp

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for swift-codable-json

README.md
[![agentmods](https://agentmods.dev/badge/skills/dagba/ios-mcp/swift-codable-json.svg)](https://agentmods.dev/skills/dagba/ios-mcp/swift-codable-json)
Your own site
<a href="https://agentmods.dev/skills/dagba/ios-mcp/swift-codable-json"><img src="https://agentmods.dev/badge/skills/dagba/ios-mcp/swift-codable-json.svg" alt="Measured on agentmods" height="20"></a>
Per session 43 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,531 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00043 $0.03531
Opus 5 $0.00022 $0.01766
Sonnet 5 $0.00009 $0.00706
Haiku 4.5 $0.00004 $0.00353

Measured 4d ago against content hash d6af7f2f94ec, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

swift-codable-json scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/swift-codable-json/SKILL.md · 523 lines

How it starts

The opening of the file, as written. The whole thing — 523 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Swift Codable for JSON Parsing

Overview

Codable provides type-safe JSON parsing but strict typing means any mismatch crashes decoding. One date strategy per decoder, CodingKeys for every naming mismatch, custom decoders for nested structures.

Core principle: Design for API reality (not ideal JSON), fail gracefully with error handling, use optionals for unreliable data.

Basic Patterns

Pattern 1: Simple Mapping

// JSON: {"id": 123, "name": "Alice", "email": "[email protected]"}

struct User: Codable {
    let id: Int
    let name: String
    let email: String
}

// Usage:
let data = jsonString.data(using: .utf8)!
let user = try JSONDecoder().decode(User.self, from: data)

Auto-synthesis works when:

  • Property names match JSON keys exactly
  • All types match (String → String, Int → Int)
  • All required properties present in JSON

Pattern 2: CodingKeys for Name Mapping

Problem: API uses snake_case, Swift uses camelCase.

// JSON: {"user_id": 123, "first_name": "Alice", "created_at": "2026-01-15"}

struct User: Codable {
    let userID: Int
    let firstName: String
    let createdAt: String

    enum CodingKeys: String, CodingKey {
        case userID = "user_id"
        case firstName = "first_name"
        case createdAt = "created_at"
    }
}

Rule: Every property must appear in CodingKeys, even if name matches.

// ❌ WRONG: Compiler error (missing properties in CodingKeys)
enum CodingKeys: String, CodingKey {
    case userID = "user_id"  // Missing firstName and createdAt
}

// ✅ CORRECT: All properties listed
enum CodingKeys: String, CodingKey {
    case userID = "user_id"
    case firstName = "first_name"
    case createdAt = "created_at"
}

Date Handling

Problem: Multiple Date Formats in Same Response

CRITICAL: JSONDecoder supports ONE date strategy at a time.

// JSON with mixed formats:
{
    "created": "2026-01-15T10:30:00Z",      // ISO8601
    "published": "15/01/2026",              // Custom format
    "timestamp": 1705316400                  // Unix timestamp
}

// ❌ WRONG: Can't set multiple strategies
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601  // Only applies to ONE field

Read the full file on GitHub · 523 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 523 lines · 43 tokens per session scan A d6af7f2f94ec

Subscribe to this mod's changes

swift-codable-json is a skill published in the GitHub repository dagba/ios-mcp (3 stars, last pushed 7mo ago), licensed MIT. It adds 43 tokens to every session and 3,531 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

kotlin-specialist

Provides idiomatic Kotlin implementation patterns including coroutine concurrency, Flow stream handling, multiplatform architecture, Compose UI construction, Ktor server setup, and type-safe DSL design. Use when building Kotlin applications requiring coroutines, multiplatform development, or Android with Compose.…

Jeffallan/claude-skills · 86 tokens

macos-swiftpm

Build, run, and test SwiftPM macOS packages and executables. Use when the repo is package-first or has no Xcode project.

robinebers/openusage · 35 tokens

kotlin-tooling-java-to-kotlin

Use when converting Java source files to idiomatic Kotlin, when user mentions "java to kotlin", "j2k", "convert java", "migrate java to kotlin", or when working with .java files that need to become .kt files. Handles framework-aware conversion for Spring, Lombok, Hibernate, Jackson, Micronaut, Quarkus, Dagger/Hilt…

Kotlin/kotlin-agent-skills · 100 tokens

signals-migration-6-to-7

Detailed guidelines, patterns, and rules for migrating codebases from signals.dart version 6.x to version 7.x.

rodydavis/signals.dart · 33 tokens

kotlin-concurrency-expert

Kotlin Coroutines review and remediation for Android. Use when asked to review concurrency usage, fix coroutine-related bugs, improve thread safety, or resolve lifecycle issues in Kotlin/Android code.

new-silvermoon/awesome-android-agent-skills · 44 tokens

android-viewmodel

Best practices for implementing Android ViewModels using Kotlin 2.3+ Explicit Backing Fields, StateFlow for UI state, and SharedFlow for one-off events.

new-silvermoon/awesome-android-agent-skills · 37 tokens