kemalcr/kemal/kemal-json
Claude Code and agent skill by kemalcr/kemal
- community
Checking that the SKILL.md file is still in the repository.
Building JSON APIs with Kemal using built-in response helpers and established project patterns.
Install
npx vskill@latest install kemalcr/kemal/kemal-jsonSKILL.md
The same SKILL.md was published earlier as kemalcr/kemal/kemal-json.
Kemal JSON API Development
This skill provides expert guidance on building robust JSON APIs with Kemal, establishing the canonical patterns for JSON response helpers and strictly following patterns from `kemal-by-example/json-api`.
Version Notes
env.jsonandenv.statusresponse helpers (symbol or integer statuses): since Kemal 1.10.- Malformed request bodies (e.g. invalid JSON) are answered with
400 Bad Requestsince Kemal 1.13.0; earlier releases return500.
Core Mandates
- Dependencies: Always
require "json". - Built-in Context Response Helpers (Kemal 1.10+): Use Kemal's built-in
env.jsonand status helpers for API responses:
```crystal # Basic JSON response (sets Content-Type to application/json; charset=utf-8 automatically) get "/api/users" do |env| env.json({users: %w[alice bob]}) end
# Symbol or integer HTTP status code with JSON: post "/api/users" do |env| env.status(:created).json({id: 1, name: "Alice"}) end
# Early halt with JSON: get "/api/protected" do |env| halt env.status(:unauthorized).json({error: "Unauthorized"}) unless authenticated?(env) end ```
- Project JsonResponse Helpers (Custom Pattern): When using standard project helpers for responses (found in
JsonApi::JsonResponse):
```crystal module JsonApi module JsonResponse extend self
def json(env : HTTP::Server::Context, status : Int32, payload : String) env.response.status_code = status env.response.content_type = "application/json; charset=utf-8" payload end
def error(env : HTTP::Server::Context, status : Int32, message : String) json(env, status, {"error" => message}.to_json) end end end ```
- Safe JSON Body Parsing: Use
env.params.raw_bodyorread_json_object(env)to safely parse JSON bodies and handle exceptions:
``crystal private def read_json_object(env : HTTP::Server::Context) : Hash(String, JSON::Any)? raw = env.params.raw_body return nil if raw.strip.empty? parsed = JSON.parse(raw) parsed.as_h? rescue JSON::ParseException nil end ``
- Serialization: Models should provide a
to_hmethod. Usemodel.to_hormodel.to_h.to_jsonfor responses.
Patterns from Source Code
API Routes with Full CRUD (json-api/src/routes/api.cr)
Best Practices
- Use Context Response Helpers: Leverage
env.jsonandenv.status(...)for idiomatic, chainable response handling. - Consistent Error Format: Always return a JSON object with an
errorkey for failure states. - Safe Field Access: Use
obj[key]?.try(&.as_s?)or similar safe accessors for fields in parsed JSON hashes. - Input Validation: Rigorously validate required fields and types before processing the request.
- Status Symbols: Use standard status symbols like
:ok,:created,:no_content,:bad_request,:unauthorized,:not_found,:unprocessable_entity.
When to Use
- When developing or refactoring API routes that return JSON.
- When handling JSON body parameters from client requests.
- When implementing standardized JSON error handling.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/kemal-json/SKILL.md
Popularity
- Repository stars
- 3,918
- Repository forks
- 205
- 7-day trend score
- 41
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kemalcr/kemal/kemal-json)