dart-json-codable
JSON पार्सिंग, सत्यापन और स्कीमा उत्पादन।
- स्टार
- 0
- फ़ोर्क
- 0
- अंतिम पुश (UTC)
- 15 सित॰ 2026
- प्रोजेक्ट स्थिति
- सक्रिय
मूल README
यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
json_codable
JSON parsing, validation, and schema generation.
Usage
Parsing & Validation (JsonObject)
JsonObject supports two parsing modes: Accumulated Validation (json.parse) and Fail-Fast (direct constructor).
import 'dart:convert';
import 'package:json_codable/json_codable.dart';
class CreateUserDto {
CreateUserDto.fromJson(JsonObject json)
: name = json.string('name', rules: [.length(min: 2)]),
email = json.string('email', rules: [.email()]),
age = json.integerOrNull('age', rules: [.range(min: 18)]);
final String name;
final String email;
final int? age;
}
final jsonString = '{"name": "A", "email": "invalid"}';
final jsonMap = jsonDecode(jsonString) as Map<String, Object?>;
final json = JsonObject(jsonMap);
// Accumulated Validation: collects ALL field errors before throwing
try {
final user = json.parse(CreateUserDto.fromJson);
} on ValidationErrors catch (error) {
print(error.toJson()); // Contains errors for both 'name' and 'email'
}
// Fail-Fast: throws immediately on the first encountered error
try {
final user = CreateUserDto.fromJson(json);
} on ValidationErrors catch (error) {
print(error.toJson()); // Contains only the first error ('name')
}
Serialization (ToJson)
Implement ToJson for DTOs and models that export to JSON maps:
class UserDto implements ToJson {
UserDto({required this.id, required this.name});
final String id;
final String name;
@override
Map<String, Object?> toJson() => {
'id': id,
'name': name,
};
}
Schema Generation
Generate JSON Schema documents directly from fromJson mappers or builder callbacks:
class CreateUserDto {
// ...
static final Schema schema = JsonObject.schema(
CreateUserDto.fromJson,
title: 'CreateUserDto',
);
}
भाषाएँDart
श्रेणियाँ
उपयोग की गई निर्भरताएँ
अपने प्रोजेक्ट के लिए रिपॉज़िटरी कैसे चुनें?
उपयोग के अनुसार छाँटें, गतिविधि की तुलना करें और अपनाने से पहले मूल प्रोजेक्ट की आवश्यकताएँ जाँचें।
- नाम, लेखक या विवरण से खोजें और तकनीकी विषय से परिणाम सीमित करें।
- स्टार, फ़ोर्क और हाल के पुश की तुलना करें। स्टार रुचि दर्शाते हैं, गुणवत्ता की गारंटी नहीं।
- उपयोग से पहले GitHub पर README, लाइसेंस और Issues जाँचें।
स्रोत और रखरखाव
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗