# Implement JSON Serialization in Flutter

Manual JSON mapping can produce runtime type errors and duplicated parsing logic. This skill guides type-safe models, HTTP parsing, validation, and isolate usage.

## Install

```bash
npx skillstore add flutter/flutter-implement-json-serialization
```

## Metadata

- Status: approved
- Slug: flutter-flutter-implement-json-serialization
- Skillstore revision: r1
- Version status: missing
- Tree hash: e35681423ce35751b3a260f7508c6bf4ca88bd55c369d75b21969c1412388040
- Author: flutter
- GitHub username: flutter
- License: MIT
- Repository: https://github.com/flutter/agent-plugins/tree/9b8106dbf09fcc1d0bda0010acc67914e6dab5e5/skills/flutter-implement-json-serialization
- Ref: d9e5ab86dafd32a1ddde9b8b4fde177589b55b95
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands, network
- Quality score: 77
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/flutter-flutter-implement-json-serialization
- Manifest: https://skillstore.pages.dev/api/skills/flutter-flutter-implement-json-serialization/manifest

## Capabilities

- Defines immutable Dart model classes that match JSON object fields.
- Implements type-safe fromJson factory constructors with explicit validation.
- Implements toJson methods that map model properties to JSON keys.
- Integrates model parsing with successful HTTP response handling.
- Moves large response parsing to a Flutter compute isolate.
- Guides unit tests for serialization and type mismatch failures.

## Use Cases

- Build a First Flutter API Model: Create a small immutable model with validated deserialization and predictable serialization.
- Integrate Typed HTTP Responses: Convert successful HTTP response bodies into application models while rejecting invalid status codes.
- Optimize Large Payload Parsing: Move expensive list decoding into a Flutter isolate to protect interface responsiveness.

## Prompt Templates

### Create a Simple Model

```
Create a Dart model for [fields]. Add a const constructor, fromJson factory, toJson method, and focused unit tests.
```

### Add Validation

```
Implement manual serialization for [model]. Validate required types and throw FormatException when the input shape is invalid.
```

### Parse an HTTP Response

```
Integrate [model] parsing into an injected Dart http client. Check response status, decode safely, and preserve testability.
```

### Handle a Large Nested Payload

```
Design manual parsing for [payload]. Include nested models, nullable fields, isolate parsing with compute, malformed input tests, and serialization round trips.
```

## Limitations

- Supports manual serialization for simple models and does not generate code.
- Requires developers to define nullability, defaults, and schema-specific validation.
- Does not cover authentication, retries, caching, or complete HTTP client design.
- Complex nested models need additional mapping logic beyond the provided examples.

## Best Practices

- Validate decoded values before constructing models.
- Inject HTTP clients so response handling remains testable.
- Use compute only when measured parsing work can block a frame.

## Anti Patterns

- Do not trust dynamic decoded values without type checks.
- Do not return null for unrelated network and parsing failures.
- Do not move small payload parsing to an isolate without measurement.

## Security Audit

- Audited at: 2026-09-08T12:38:00.219\+00:00
- Summary: All 21 external-command detections are Markdown backticks around Dart identifiers or fenced Dart examples, not shell execution. Both URLs use the reserved example.com domain in sample requests. No prompt injection, exfiltration intent, or other semantic threat was found.

## Stats

- Views: 0
- Downloads: 2
- Favorites: 0
- Popularity score: 0
