Skip to content
Back to skills

Json Serialization

ASecurity

Standardizes JSON serialization and deserialization in Flutter and Dart using dart:convert, manual factory constructors, or code-generation with freezed.

  • 6 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 7, 2026
ai-agentsapi

Works with

  • api

Security analysis

A100/100

Scanned September 7, 2026

npx -y skills add smicolon/ai-kit --skill json-serialization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Json Serialization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Json Serialization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/smicolon-json-serialization/badge)](https://www.skillsdirectory.com/skills/smicolon-json-serialization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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();
}
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.