Standardizes JSON serialization and deserialization in Flutter and Dart using dart:convert, manual factory constructors, or code-generation with freezed.
Scanned 9/7/2026
Install to Claude Code
npx -y skills add smicolon/ai-kit --skill json-serialization --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Json Serialization?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/smicolon-json-serialization)More formats (shields.io, HTML) on the badges page.
---
name: json-serialization
description: Standardizes JSON serialization and deserialization in Flutter and Dart using dart:convert, manual factory constructors, or code-generation with freezed.
version: 1.0.0
---
# JSON Serialization in Flutter
Best practices for mapping API JSON payloads to Dart models safely.
## 1. Immutable Model Pattern (No Code-Gen)
Ideal for simple to medium entities without heavy dependencies:
```dart
class UserModel {
final String id;
final String email;
final String? displayName;
final DateTime createdAt;
const UserModel({
required this.id,
required this.email,
this.displayName,
required this.createdAt,
});
factory UserModel.fromJson(Map<String, dynamic> json) {
return UserModel(
id: json['id'] as String,
email: json['email'] as String,
displayName: json['display_name'] as String?,
createdAt: DateTime.parse(json['created_at'] as String),
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'email': email,
if (displayName != null) 'display_name': displayName,
'created_at': createdAt.toIso8601String(),
};
}
UserModel copyWith({
String? id,
String? email,
String? displayName,
DateTime? createdAt,
}) {
return UserModel(
id: id ?? this.id,
email: email ?? this.email,
displayName: displayName ?? this.displayName,
createdAt: createdAt ?? this.createdAt,
);
}
}
```
## 2. Safe Parsing Helper
Always guard against nulls or unexpected types from network responses:
```dart
int parseCount(dynamic value) {
if (value is int) return value;
if (value is String) return int.tryParse(value) ?? 0;
return 0;
}
```
## 3. List Parsing Pattern
```dart
List<UserModel> parseUsers(List<dynamic> list) {
return list
.whereType<Map<String, dynamic>>()
.map(UserModel.fromJson)
.toList();
}
```
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!