[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BVA34W4QE415N4KMEC13RW":3,"skill-same:01M7BVA34W4QE415N4KMEC13RW":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":31,"ownerHtmlUrl":32,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":33,"install":34,"resources":47},"01M7BVA34W4QE415N4KMEC13RW","flutter-implement-json-serialization",null,"Create model classes with `fromJson` and `toJson` methods using `dart:convert`. Use when manually mapping JSON keys to class properties for simple data structures.","nguyenhungtran18\u002Fskill-and-tool-tracker","nguyenhungtran18","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F297063550?v=4","01M7BV0BFPRRFP84F2ME0FYZ9D","01M7BV0BG83FA5P22NJV0GR0A5",1,"MIT","https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18\u002Fskill-and-tool-tracker\u002Fblob\u002Fmain\u002Fskills\u002Fflutter-implement-json-serialization\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: flutter-implement-json-serialization\ndescription: Create model classes with `fromJson` and `toJson` methods using `dart:convert`. Use when manually mapping JSON keys to class properties for simple data structures.\nmetadata:\n  model: models\u002Fgemini-3.1-pro-preview\n  last_modified: Tue, 21 Apr 2026 21:44:50 GMT\n---\n# Serializing JSON Manually in Flutter\n\n## Contents\n- [Core Guidelines](#core-guidelines)\n- [Workflow: Implementing a Serializable Model](#workflow-implementing-a-serializable-model)\n- [Workflow: Fetching and Parsing JSON](#workflow-fetching-and-parsing-json)\n- [Examples](#examples)\n\n## Core Guidelines\n\n- **Import `dart:convert`**: Utilize Flutter's built-in `dart:convert` library for manual JSON encoding (`jsonEncode`) and decoding (`jsonDecode`).\n- **Enforce Type Safety**: Always cast the `dynamic` result of `jsonDecode()` to the expected type, typically `Map\u003CString, dynamic>` for objects or `List\u003Cdynamic>` for arrays.\n- **Encapsulate Serialization Logic**: Define plain model classes containing properties corresponding to the JSON structure. Implement a `fromJson` factory constructor and a `toJson` method within the model.\n- **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.\n- **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`.\n\n## Workflow: Implementing a Serializable Model\n\nUse this checklist to implement manual JSON serialization for a data model.\n\n**Task Progress:**\n- [ ] Define the plain model class with `final` properties.\n- [ ] Implement the `factory Model.fromJson(Map\u003CString, dynamic> json)` constructor.\n- [ ] Implement the `Map\u003CString, dynamic> toJson()` method.\n- [ ] Write unit tests for both serialization methods.\n- [ ] Run validator -> review type mismatch errors -> fix casting logic.\n\n1. **Define the Model**: Create a class with properties matching the JSON keys.\n2. **Implement `fromJson`**: Extract values from the `Map` and cast them to the appropriate Dart types. Use pattern matching or explicit casting.\n3. **Implement `toJson`**: Return a `Map\u003CString, dynamic>` mapping the class properties back to their JSON string keys.\n4. **Validate**: Execute unit tests to ensure type safety, autocompletion, and compile-time exception handling function correctly.\n\n## Workflow: Fetching and Parsing JSON\n\nUse this conditional workflow when retrieving and parsing JSON from a network request.\n\n**Task Progress:**\n- [ ] Execute the HTTP request.\n- [ ] Validate the response status code.\n- [ ] Determine parsing strategy (Synchronous vs. Isolate).\n- [ ] Decode and map the JSON to the model.\n\n1. **Execute Request**: Use the `http` package to perform the network call.\n2. **Validate Response**: \n   - If `response.statusCode == 200` (or 201 for POST), proceed to parsing.\n   - If the status code indicates failure, throw an `Exception`.\n3. **Determine Parsing Strategy**:\n   - If parsing a **small payload** (e.g., a single object), parse synchronously on the main thread.\n   - If parsing a **large payload** (e.g., an array of thousands of objects), use `compute(parseFunction, response.body)` to parse in a background isolate.\n4. **Decode and Map**: Pass the decoded JSON to your model's `fromJson` constructor.\n\n## Examples\n\n### High-Fidelity Model Implementation\n\n```dart\nimport 'dart:convert';\n\nclass User {\n  final int id;\n  final String name;\n  final String email;\n\n  const User({\n    required this.id,\n    required this.name,\n    required this.email,\n  });\n\n  \u002F\u002F Factory constructor for deserialization\n  factory User.fromJson(Map\u003CString, dynamic> json) {\n    return switch (json) {\n      {\n        'id': int id,\n        'name': String name,\n        'email': String email,\n      } => \n        User(\n          id: id,\n          name: name,\n          email: email,\n        ),\n      _ => throw const FormatException('Failed to load User.'),\n    };\n  }\n\n  \u002F\u002F Method for serialization\n  Map\u003CString, dynamic> toJson() {\n    return {\n      'id': id,\n      'name': name,\n      'email': email,\n    };\n  }\n}\n```\n\n### Synchronous Parsing (Small Payload)\n\n```dart\nimport 'dart:convert';\nimport 'package:http\u002Fhttp.dart' as http;\n\nFuture\u003CUser> fetchUser(http.Client client, int userId) async {\n  final response = await client.get(\n    Uri.parse('https:\u002F\u002Fapi.example.com\u002Fusers\u002F$userId'),\n    headers: {'Accept': 'application\u002Fjson'},\n  );\n\n  if (response.statusCode == 200) {\n    \u002F\u002F Decode returns dynamic, cast to Map\u003CString, dynamic>\n    final Map\u003CString, dynamic> jsonMap = jsonDecode(response.body) as Map\u003CString, dynamic>;\n    return User.fromJson(jsonMap);\n  } else {\n    throw Exception('Failed to load user');\n  }\n}\n```\n\n### Background Parsing (Large Payload)\n\n```dart\nimport 'dart:convert';\nimport 'package:flutter\u002Ffoundation.dart';\nimport 'package:http\u002Fhttp.dart' as http;\n\n\u002F\u002F Top-level function required for compute()\nList\u003CUser> parseUsers(String responseBody) {\n  final parsed = (jsonDecode(responseBody) as List\u003Cdynamic>).cast\u003CMap\u003CString, dynamic>>();\n  return parsed.map\u003CUser>((json) => User.fromJson(json)).toList();\n}\n\nFuture\u003CList\u003CUser>> fetchUsers(http.Client client) async {\n  final response = await client.get(\n    Uri.parse('https:\u002F\u002Fapi.example.com\u002Fusers'),\n    headers: {'Accept': 'application\u002Fjson'},\n  );\n\n  if (response.statusCode == 200) {\n    \u002F\u002F Offload expensive parsing to a background isolate\n    return compute(parseUsers, response.body);\n  } else {\n    throw Exception('Failed to load users');\n  }\n}\n```\n","# Serializing JSON Manually in Flutter\n\n## Contents\n- [Core Guidelines](#core-guidelines)\n- [Workflow: Implementing a Serializable Model](#workflow-implementing-a-serializable-model)\n- [Workflow: Fetching and Parsing JSON](#workflow-fetching-and-parsing-json)\n- [Examples](#examples)\n\n## Core Guidelines\n\n- **Import `dart:convert`**: Utilize Flutter's built-in `dart:convert` library for manual JSON encoding (`jsonEncode`) and decoding (`jsonDecode`).\n- **Enforce Type Safety**: Always cast the `dynamic` result of `jsonDecode()` to the expected type, typically `Map\u003CString, dynamic>` for objects or `List\u003Cdynamic>` for arrays.\n- **Encapsulate Serialization Logic**: Define plain model classes containing properties corresponding to the JSON structure. Implement a `fromJson` factory constructor and a `toJson` method within the model.\n- **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.\n- **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`.\n\n## Workflow: Implementing a Serializable Model\n\nUse this checklist to implement manual JSON serialization for a data model.\n\n**Task Progress:**\n- [ ] Define the plain model class with `final` properties.\n- [ ] Implement the `factory Model.fromJson(Map\u003CString, dynamic> json)` constructor.\n- [ ] Implement the `Map\u003CString, dynamic> toJson()` method.\n- [ ] Write unit tests for both serialization methods.\n- [ ] Run validator -> review type mismatch errors -> fix casting logic.\n\n1. **Define the Model**: Create a class with properties matching the JSON keys.\n2. **Implement `fromJson`**: Extract values from the `Map` and cast them to the appropriate Dart types. Use pattern matching or explicit casting.\n3. **Implement `toJson`**: Return a `Map\u003CString, dynamic>` mapping the class properties back to their JSON string keys.\n4. **Validate**: Execute unit tests to ensure type safety, autocompletion, and compile-time exception handling function correctly.\n\n## Workflow: Fetching and Parsing JSON\n\nUse this conditional workflow when retrieving and parsing JSON from a network request.\n\n**Task Progress:**\n- [ ] Execute the HTTP request.\n- [ ] Validate the response status code.\n- [ ] Determine parsing strategy (Synchronous vs. Isolate).\n- [ ] Decode and map the JSON to the model.\n\n1. **Execute Request**: Use the `http` package to perform the network call.\n2. **Validate Response**: \n   - If `response.statusCode == 200` (or 201 for POST), proceed to parsing.\n   - If the status code indicates failure, throw an `Exception`.\n3. **Determine Parsing Strategy**:\n   - If parsing a **small payload** (e.g., a single object), parse synchronously on the main thread.\n   - If parsing a **large payload** (e.g., an array of thousands of objects), use `compute(parseFunction, response.body)` to parse in a background isolate.\n4. **Decode and Map**: Pass the decoded JSON to your model's `fromJson` constructor.\n\n## Examples\n\n### High-Fidelity Model Implementation\n\n```dart\nimport 'dart:convert';\n\nclass User {\n  final int id;\n  final String name;\n  final String email;\n\n  const User({\n    required this.id,\n    required this.name,\n    required this.email,\n  });\n\n  \u002F\u002F Factory constructor for deserialization\n  factory User.fromJson(Map\u003CString, dynamic> json) {\n    return switch (json) {\n      {\n        'id': int id,\n        'name': String name,\n        'email': String email,\n      } => \n        User(\n          id: id,\n          name: name,\n          email: email,\n        ),\n      _ => throw const FormatException('Failed to load User.'),\n    };\n  }\n\n  \u002F\u002F Method for serialization\n  Map\u003CString, dynamic> toJson() {\n    return {\n      'id': id,\n      'name': name,\n      'email': email,\n    };\n  }\n}\n```\n\n### Synchronous Parsing (Small Payload)\n\n```dart\nimport 'dart:convert';\nimport 'package:http\u002Fhttp.dart' as http;\n\nFuture\u003CUser> fetchUser(http.Client client, int userId) async {\n  final response = await client.get(\n    Uri.parse('https:\u002F\u002Fapi.example.com\u002Fusers\u002F$userId'),\n    headers: {'Accept': 'application\u002Fjson'},\n  );\n\n  if (response.statusCode == 200) {\n    \u002F\u002F Decode returns dynamic, cast to Map\u003CString, dynamic>\n    final Map\u003CString, dynamic> jsonMap = jsonDecode(response.body) as Map\u003CString, dynamic>;\n    return User.fromJson(jsonMap);\n  } else {\n    throw Exception('Failed to load user');\n  }\n}\n```\n\n### Background Parsing (Large Payload)\n\n```dart\nimport 'dart:convert';\nimport 'package:flutter\u002Ffoundation.dart';\nimport 'package:http\u002Fhttp.dart' as http;\n\n\u002F\u002F Top-level function required for compute()\nList\u003CUser> parseUsers(String responseBody) {\n  final parsed = (jsonDecode(responseBody) as List\u003Cdynamic>).cast\u003CMap\u003CString, dynamic>>();\n  return parsed.map\u003CUser>((json) => User.fromJson(json)).toList();\n}\n\nFuture\u003CList\u003CUser>> fetchUsers(http.Client client) async {\n  final response = await client.get(\n    Uri.parse('https:\u002F\u002Fapi.example.com\u002Fusers'),\n    headers: {'Accept': 'application\u002Fjson'},\n  );\n\n  if (response.statusCode == 200) {\n    \u002F\u002F Offload expensive parsing to a background isolate\n    return compute(parseUsers, response.body);\n  } else {\n    throw Exception('Failed to load users');\n  }\n}\n```\n",{"name":5,"metadata":23,"description":7},{"model":24,"last_modified":25},"models\u002Fgemini-3.1-pro-preview","Tue, 21 Apr 2026 21:44:50 GMT","main","900ea3c9eb045fd5b0317dc1103777ecf3ea4aeb","skills\u002Fflutter-implement-json-serialization",0,"https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18\u002Fskill-and-tool-tracker","https:\u002F\u002Fnguyenhungtran18.github.io\u002Fskill-and-tool-tracker\u002F","https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18","2026-08-31 18:36:09",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add nguyenhungtran18\u002Fskill-and-tool-tracker --skill flutter-implement-json-serialization",{"tool":40,"command":41},"bunx","bunx skills add nguyenhungtran18\u002Fskill-and-tool-tracker --skill flutter-implement-json-serialization",{"tool":43,"command":44},"pnpm","pnpm dlx skills add nguyenhungtran18\u002Fskill-and-tool-tracker --skill flutter-implement-json-serialization","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18\u002Fskill-and-tool-tracker\u002Fblob\u002Fmain\u002Fskills\u002Fflutter-implement-json-serialization\u002FSKILL.md",true,[],[49,56,63,70,77,84],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":18},"01M7BVP4P83TK60JZ4P8RP9VP7","xcode-project-setup","Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).","https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18\u002Fskill-and-tool-tracker\u002Fblob\u002Fmain\u002Fskills\u002Fxcode_project_setup\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":18},"01M7BVP01K4CSJJ8G90FT8S2D5","writing-skills","Use when creating new skills, editing existing skills, or verifying skills work before deployment","https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18\u002Fskill-and-tool-tracker\u002Fblob\u002Fmain\u002Fskills\u002Fwriting-skills\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":18},"01M7BVNY22GXD871GYTSH599F1","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18\u002Fskill-and-tool-tracker\u002Fblob\u002Fmain\u002Fskills\u002Fwriting-plans\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":18},"01M7BVNQWF24RNKA8A4KM2HJ3T","workflow-skill-creator","Distills a completed user workflow or interaction into a reusable agent skill. Use when the user asks to turn their workflow, interaction, or multi-step process into a skill, or when they say \"make this a skill\", \"create a skill from what we just did\", \"package this workflow\" or similar. Do not use for creating skills from scratch without an existing workflow (use a generic skill-creator for that).","https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18\u002Fskill-and-tool-tracker\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow_skill_creator\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":18},"01M7BVNNY67XPCQAQHY3FBKDGC","verify-and-stop","Prove existing work meets acceptance conditions without expanding scope. Use for validation-only tasks, completion checks, focused gate runs, and last-mile proof.","https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18\u002Fskill-and-tool-tracker\u002Fblob\u002Fmain\u002Fskills\u002Fverify-and-stop\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":18},"01M7BVNKB4Z7SZT85B73ZZ90Y6","verification-before-completion","Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always","https:\u002F\u002Fgithub.com\u002Fnguyenhungtran18\u002Fskill-and-tool-tracker\u002Fblob\u002Fmain\u002Fskills\u002Fverification-before-completion\u002FSKILL.md",[],[]]