dart-json-codable
JSON 파싱, 검증 및 스키마 생성.
- 스타
- 0
- 포크
- 0
- 최근 푸시(UTC)
- 2026. 9. 15.
- 프로젝트 상태
- 활성
원본 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 ↗