techia-dev/system/flutter-implement-json-serialization
Claude Code and agent skill by techia-dev/system
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Create model classes with `fromJson` and `toJson` methods using `dart:convert`. Use when manually mapping JSON keys to class properties for simple data structures.
Install
npx vskill@latest install techia-dev/system/flutter-implement-json-serializationSKILL.md
The same SKILL.md was published earlier as flutter/skills/flutter-implement-json-serialization.
Serializing JSON Manually in Flutter
Contents
- Core Guidelines
- Workflow: Implementing a Serializable Model
- Workflow: Fetching and Parsing JSON
- Examples
Core Guidelines
- Import `dart:convert`: Utilize Flutter's built-in
dart:convertlibrary for manual JSON encoding (jsonEncode) and decoding (jsonDecode). - Enforce Type Safety: Always cast the
dynamicresult ofjsonDecode()to the expected type, typicallyMap<String, dynamic>for objects orList<dynamic>for arrays. - Encapsulate Serialization Logic: Define plain model classes containing properties corresponding to the JSON structure. Implement a
fromJsonfactory constructor and atoJsonmethod within the model. - Handle Background Parsing: If parsing large JSON documents (execution time > 16ms), offload the parsing logic to a separate isolate using Flutter's
compute()function to prevent UI jank. - Throw Exceptions on Failure: When handling HTTP responses, throw an exception if the status code is not successful (e.g., not 200 OK or 201 Created). Do not return
null.
Workflow: Implementing a Serializable Model
Use this checklist to implement manual JSON serialization for a data model.
Task Progress:
- [ ] Define the plain model class with
finalproperties. - [ ] Implement the
factory Model.fromJson(Map<String, dynamic> json)constructor. - [ ] Implement the
Map<String, dynamic> toJson()method. - [ ] Write unit tests for both serialization methods.
- [ ] Run validator -> review type mismatch errors -> fix casting logic.
- Define the Model: Create a class with properties matching the JSON keys.
- Implement `fromJson`: Extract values from the
Mapand cast them to the appropriate Dart types. Use pattern matching or explicit casting. - Implement `toJson`: Return a
Map<String, dynamic>mapping the class properties back to their JSON string keys. - Validate: Execute unit tests to ensure type safety, autocompletion, and compile-time exception handling function correctly.
Workflow: Fetching and Parsing JSON
Use this conditional workflow when retrieving and parsing JSON from a network request.
Task Progress:
- [ ] Execute the HTTP request.
- [ ] Validate the response status code.
- [ ] Determine parsing strategy (Synchronous vs. Isolate).
- [ ] Decode and map the JSON to the model.
- Execute Request: Use the
httppackage to perform the network call. - Validate Response:
- If
response.statusCode == 200(or 201 for POST), proceed to parsing. - If the status code indicates failure, throw an
Exception.
- Determine Parsing Strategy:
- If parsing a small payload (e.g., a single object), parse synchronously on the main thread.
- If parsing a large payload (e.g., an array of thousands of objects), use
compute(parseFunction, response.body)to parse in a background isolate.
- Decode and Map: Pass the decoded JSON to your model's
fromJsonconstructor.
Examples
High-Fidelity Model Implementation
Synchronous Parsing (Small Payload)
Background Parsing (Large Payload)
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingapps/mobile/Project/.agents/skills/flutter-implement-json-serialization/SKILL.md
Popularity
- 7-day trend score
- 0
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/techia-dev/system/flutter-implement-json-serialization)