toJson method

Map<String, dynamic> toJson()

Converts this User instance to a JSON object.

This method is used to serialize user data for API requests or local storage. It converts all the user properties to JSON-compatible types.

Returns

A Map containing the user data in JSON format

Example

final user = User(id: 123, email: 'user@example.com', createdAt: DateTime.now());
final json = user.toJson();
print(json); // {'id': 123, 'email': 'user@example.com', ...}

Implementation

Map<String, dynamic> toJson() {
  return {
    'id': id,
    'email': email,
    'name': name,
    'avatar': avatar,
    'tags': tags,
    'createdAt': createdAt.toIso8601String(),
  };
}