{"id":32300233,"url":"https://github.com/wilinz/json5_model","last_synced_at":"2026-02-22T00:02:05.794Z","repository":{"id":127291731,"uuid":"611209935","full_name":"wilinz/json5_model","owner":"wilinz","description":"A one-line command to convert a JSON file into a Dart model class.","archived":false,"fork":false,"pushed_at":"2025-04-30T17:02:22.000Z","size":235,"stargazers_count":11,"open_issues_count":7,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-11T16:33:10.418Z","etag":null,"topics":["dart","flutter","json","json2dart","json5"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/json5_model","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wilinz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-03-08T10:56:23.000Z","updated_at":"2025-04-30T17:02:26.000Z","dependencies_parsed_at":"2023-10-14T18:23:09.931Z","dependency_job_id":"e9bee53e-e808-4a9f-b46c-c37dba756f58","html_url":"https://github.com/wilinz/json5_model","commit_stats":{"total_commits":26,"total_committers":4,"mean_commits":6.5,"dds":0.6153846153846154,"last_synced_commit":"e29702a28e6875bb45fd275123cf869c73ead266"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/wilinz/json5_model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilinz%2Fjson5_model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilinz%2Fjson5_model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilinz%2Fjson5_model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilinz%2Fjson5_model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wilinz","download_url":"https://codeload.github.com/wilinz/json5_model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilinz%2Fjson5_model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29699335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T23:35:04.139Z","status":"ssl_error","status_checked_at":"2026-02-21T23:35:03.832Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flutter","json","json2dart","json5"],"created_at":"2025-10-23T05:14:21.964Z","updated_at":"2026-02-22T00:02:05.788Z","avatar_url":"https://github.com/wilinz.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"Language: [English](README.md) | [简体中文](README-ZH.md)\n\n# json5_model\n\nConvert JSON files to Dart model classes with a single command\n\nAn improved version of json_model that supports nested JSON parsing, JSON5 files, and fixes several\nbugs. Note: The original @meta functionality from json_model is not supported.\n\n## Installation\n\nUnix bash:\n\n```shell\ndart pub add \\\njson_annotation copy_with_extension equatable equatable_annotations \\\ndev:json5_model dev:json_serializable dev:copy_with_extension_gen dev:equatable_gen dev:build_runner\n```\n\nWindows Powershell:\n\n```shell\ndart pub add |\njson_annotation copy_with_extension equatable equatable_annotations |\ndev:json5_model dev:json_serializable dev:copy_with_extension_gen dev:equatable_gen dev:build_runner\n```\n\n---\n\n## Version 5.0.0 and above: Use `equatable_gen` by default to replace\n`autoequal`, migration method as follows:\n\nThere is a quick way to migrate the old code to `equatable_gen`.  \nUse the `--dist` parameter to specify the directory for the Dart model source code. Before\nmigrating, a backup will be automatically created. You can specify the backup directory using the\n`--migr-autoequal-back \u003cbackup_dir\u003e` parameter. If not specified, the default backup directory is\n`./migr_autoequal_back`.\n\n```shell\ndart pub run json5_model --dist=lib/data/model --migr-autoequal\n```\n\nYou can also migrate manually by replacing the following:\n\n1. `@Autoequal()` =\u003e `@generateProps`\n2. `@autoequal`  =\u003e  `@generateProps`\n3. `@IgnoreAutoequal()` =\u003e `@ignore`\n4. `@IncludeAutoequal()` =\u003e `@include`\n5. replace import:\n\n```dart\nimport 'package:autoequal/autoequal.dart';\n```\n\n=\u003e\n\n```dart\nimport 'package:equatable_annotations/equatable_annotations.dart';\n```\n\n---\n\n## Usage\n\n1. Create a directory named \"json\" in your project root\n2. Create or copy JSON files into the \"json\" directory\n3. Examples:\n\n```shell\n# Custom paths\nflutter pub run json5_model --src=lib/data/json --dist=lib/data/model\n\n# Use RegExp to extract class name prefix from filenames (e.g. remove \"_response\" suffix)\nflutter pub run json5_model  --src=lib/data/json --dist=lib/test/json --prefix-regexp \"(.+?)_response$\"\n\n# Keep source files\nflutter pub run json5_model --src=lib/data/json --dist=lib/data/model --keepsource\n\n# Restore files\nflutter pub run json5_model --src=lib/data/json --restore\n```\n\n## New Features\n\n### File Restoration Command\n\nUse the `--restore` parameter to restore all renamed JSON files:\n\n```shell\nflutter pub run json5_model --restore\n```\n\n### Keep Source Files\n\nAdd the `--keepsource` parameter to prevent automatic renaming of JSON files:\n\n```shell\nflutter pub run json5_model --keepsource\n```\n\n## Global Command Parameters\n\n| Parameter               | Description                                                                                                   | Default Value         |\n|-------------------------|---------------------------------------------------------------------------------------------------------------|-----------------------|\n| `--src`                 | Specify JSON source directory                                                                                 | ./jsons               |\n| `--dist`                | Specify output directory                                                                                      | lib/models            |\n| `--nocopywith`          | Disable copyWith method generation                                                                            | false                 |\n| `--noautoequal`         | Disable equality comparison generation                                                                        | false                 |\n| `--keepsource`          | Keep original JSON files (don't add _ prefix) after generation                                                | false                 |\n| `--restore`             | Restore all renamed JSON files                                                                                | false                 |\n| `--clean`               | Clean generated files                                                                                         | false                 |\n| `--no-file-prefix`      | Disable auto-adding class name prefixes (may cause name conflicts)                                            | false                 |\n| `--prefix-regexp`       | Apply RegExp to filename to extract class name prefix                                                         | (.+?)                 |\n| `--migr-autoequal`      | Enable migration for the old version of autoequal.                                                            | false                 |\n| `--migr-autoequal-back` | Specify the backup directory when migrating the old version of autoequal. Default is \"./migr_autoequal_back\". | ./migr_autoequal_back |\n\n## How It Works\n\n1. **Smart Type Inference**  \n   Automatically detects and merges these type characteristics:\n    - Numeric type promotion (int → double)\n    - Handles nested objects and lists\n    - Automatic null safety handling\n    - Merges fields from multiple JSON structures\n\n2. **File Management**\n    - By default adds \"_\" prefix to source JSON files after generation (can be disabled with\n      `--keepsource`)\n    - Use `--restore` to batch restore renamed files\n\n3. **Advanced Features**\n   ```dart\n   // Auto-generated extension methods\n   List\u003cGithub\u003e githubListFormJson(List json) =\u003e ... \n   \n   // Empty object construction\n   factory Github.emptyInstance() =\u003e Github(...);\n   \n   // Deep copy support\n   Github newObj = oldObj.copyWith(id: 123);\n   ```\n\n## Example JSON → Dart Conversion\n\nInput JSON:\n\n```json5\n{\n  \"scores\": [\n    90,\n    85.5,\n    null\n  ],\n  \"users\": [\n    {\n      \"name\": \"Alice\",\n      \"age\": 25\n    },\n    {\n      \"name\": \"Bob\",\n      \"height\": 175.5\n    }\n  ]\n}\n```\n\nGenerated Dart snippet:\n\n```dart\n// Automatic numeric type and nullable handling\nList\u003cdouble?\u003e scores;\n\n// Merges Map fields from different structures\nclass UsersItem {\n  String? name;\n  int? age;\n  double? height;\n\n  factory UsersItem.fromJson(Map\u003cString, dynamic\u003e json) =\u003e\n\n  ...\n}\n```\n\n## Best Practices\n\n1. **Version Control**  \n   Recommend including original JSON files in version control (with proper data sanitization)\n\n2. **CI Integration**  \n   Add generation command to your CI pipeline:\n   ```yaml\n   # GitHub Actions example\n   - name: Generate models\n     run: flutter pub run json5_model\n   ```\n\n3. **Mixed Type Handling**  \n   When encountering incompatible types:\n   ```dart\n   // Automatically falls back to dynamic type\n   List\u003cdynamic\u003e complexList;\n   ```\n\n4. **Custom Configuration**  \n   Combine parameters for customized generation:\n   ```shell\n   # Disable autoequal and copywith generation\n   flutter pub run json5_model --noautoequal --nocopywith\n   ```\n\n## Example:\n\n```shell\nflutter pub run json5_model --src=lib/data/json\n```\n\njson:\n\n```json5\n{\n  \"id\": 1296269,\n  \"node_id\": \"MDEwOlJlcG9zaXRvcnkxMjk2MjY5\",\n  \"owner\": {\n    \"login\": \"octocat\",\n  },\n  \"private\": false,\n  \"topics\": [\n    \"octocat\",\n    \"atom\",\n    \"electron\",\n    \"api\"\n  ],\n  \"permissions\": {\n    \"admin\": false,\n    \"push\": false,\n    \"pull\": true\n  },\n  \"security_and_analysis\": {\n    \"advanced_security\": {\n      \"status\": \"enabled\"\n    },\n    \"secret_scanning\": {\n      \"status\": \"enabled\"\n    },\n    \"secret_scanning_push_protection\": {\n      \"status\": \"disabled\"\n    }\n  }\n}\n```\n\nDart:\n\n```dart\nimport 'package:json_annotation/json_annotation.dart';\nimport 'package:copy_with_extension/copy_with_extension.dart';\nimport 'package:equatable/equatable.dart';\nimport 'package:autoequal/autoequal.dart';\n\npart 'github.g.dart';\n\n@CopyWith()\n@Autoequal()\n@JsonSerializable(explicitToJson: true)\nclass Github\n    with EquatableMixin {\n\n  Github({required this.id,\n    required this.nodeId,\n    required this.owner,\n    required this.private,\n    required this.topics,\n    required this.permissions,\n    required this.securityAndAnalysis});\n\n  @JsonKey(name: \"id\", defaultValue: 0)\n  final int id;\n\n  @JsonKey(name: \"node_id\", defaultValue: \"\")\n  final String nodeId;\n\n  @JsonKey(name: \"owner\", defaultValue: Owner.emptyInstance)\n  final Owner owner;\n\n  @JsonKey(name: \"private\", defaultValue: false)\n  final bool private;\n\n  @JsonKey(name: \"topics\", defaultValue: [])\n  final List\u003cString\u003e topics;\n\n  @JsonKey(name: \"permissions\", defaultValue: Permissions.emptyInstance)\n  final Permissions permissions;\n\n  @JsonKey(name: \"security_and_analysis\", defaultValue: SecurityAndAnalysis.emptyInstance)\n  final SecurityAndAnalysis securityAndAnalysis;\n\n\n  factory Github.fromJson(Map\u003cString, dynamic\u003e json) =\u003e _$GithubFromJson(json);\n\n  Map\u003cString, dynamic\u003e toJson() =\u003e _$GithubToJson(this);\n\n  factory Github.emptyInstance() =\u003e\n      Github(id: 0,\n          nodeId: \"\",\n          owner: Owner.emptyInstance(),\n          private: false,\n          topics: [],\n          permissions: Permissions.emptyInstance(),\n          securityAndAnalysis: SecurityAndAnalysis.emptyInstance());\n\n  @override\n  List\u003cObject?\u003e get props =\u003e _$props;\n}\n\n@CopyWith()\n@Autoequal()\n@JsonSerializable(explicitToJson: true)\nclass Owner\n    with EquatableMixin {\n\n  Owner({required this.login});\n\n  @JsonKey(name: \"login\", defaultValue: \"\")\n  final String login;\n\n\n  factory Owner.fromJson(Map\u003cString, dynamic\u003e json) =\u003e _$OwnerFromJson(json);\n\n  Map\u003cString, dynamic\u003e toJson() =\u003e _$OwnerToJson(this);\n\n  factory Owner.emptyInstance() =\u003e Owner(login: \"\");\n\n  @override\n  List\u003cObject?\u003e get props =\u003e _$props;\n}\n\n@CopyWith()\n@Autoequal()\n@JsonSerializable(explicitToJson: true)\nclass Permissions\n    with EquatableMixin {\n\n  Permissions({required this.admin,\n    required this.push,\n    required this.pull});\n\n  @JsonKey(name: \"admin\", defaultValue: false)\n  final bool admin;\n\n  @JsonKey(name: \"push\", defaultValue: false)\n  final bool push;\n\n  @JsonKey(name: \"pull\", defaultValue: false)\n  final bool pull;\n\n\n  factory Permissions.fromJson(Map\u003cString, dynamic\u003e json) =\u003e _$PermissionsFromJson(json);\n\n  Map\u003cString, dynamic\u003e toJson() =\u003e _$PermissionsToJson(this);\n\n  factory Permissions.emptyInstance() =\u003e Permissions(admin: false, push: false, pull: false);\n\n  @override\n  List\u003cObject?\u003e get props =\u003e _$props;\n}\n\n@CopyWith()\n@Autoequal()\n@JsonSerializable(explicitToJson: true)\nclass AdvancedSecurity\n    with EquatableMixin {\n\n  AdvancedSecurity({required this.status});\n\n  @JsonKey(name: \"status\", defaultValue: \"\")\n  final String status;\n\n\n  factory AdvancedSecurity.fromJson(Map\u003cString, dynamic\u003e json) =\u003e _$AdvancedSecurityFromJson(json);\n\n  Map\u003cString, dynamic\u003e toJson() =\u003e _$AdvancedSecurityToJson(this);\n\n  factory AdvancedSecurity.emptyInstance() =\u003e AdvancedSecurity(status: \"\");\n\n  @override\n  List\u003cObject?\u003e get props =\u003e _$props;\n}\n\n@CopyWith()\n@Autoequal()\n@JsonSerializable(explicitToJson: true)\nclass SecretScanning\n    with EquatableMixin {\n\n  SecretScanning({required this.status});\n\n  @JsonKey(name: \"status\", defaultValue: \"\")\n  final String status;\n\n\n  factory SecretScanning.fromJson(Map\u003cString, dynamic\u003e json) =\u003e _$SecretScanningFromJson(json);\n\n  Map\u003cString, dynamic\u003e toJson() =\u003e _$SecretScanningToJson(this);\n\n  factory SecretScanning.emptyInstance() =\u003e SecretScanning(status: \"\");\n\n  @override\n  List\u003cObject?\u003e get props =\u003e _$props;\n}\n\n@CopyWith()\n@Autoequal()\n@JsonSerializable(explicitToJson: true)\nclass SecretScanningPushProtection\n    with EquatableMixin {\n\n  SecretScanningPushProtection({required this.status});\n\n  @JsonKey(name: \"status\", defaultValue: \"\")\n  final String status;\n\n\n  factory SecretScanningPushProtection.fromJson(Map\u003cString, dynamic\u003e json) =\u003e\n      _$SecretScanningPushProtectionFromJson(json);\n\n  Map\u003cString, dynamic\u003e toJson() =\u003e _$SecretScanningPushProtectionToJson(this);\n\n  factory SecretScanningPushProtection.emptyInstance() =\u003e SecretScanningPushProtection(status: \"\");\n\n  @override\n  List\u003cObject?\u003e get props =\u003e _$props;\n}\n\n@CopyWith()\n@Autoequal()\n@JsonSerializable(explicitToJson: true)\nclass SecurityAndAnalysis\n    with EquatableMixin {\n\n  SecurityAndAnalysis({required this.advancedSecurity,\n    required this.secretScanning,\n    required this.secretScanningPushProtection});\n\n  @JsonKey(name: \"advanced_security\", defaultValue: AdvancedSecurity.emptyInstance)\n  final AdvancedSecurity advancedSecurity;\n\n  @JsonKey(name: \"secret_scanning\", defaultValue: SecretScanning.emptyInstance)\n  final SecretScanning secretScanning;\n\n  @JsonKey(name: \"secret_scanning_push_protection\",\n      defaultValue: SecretScanningPushProtection.emptyInstance)\n  final SecretScanningPushProtection secretScanningPushProtection;\n\n\n  factory SecurityAndAnalysis.fromJson(Map\u003cString, dynamic\u003e json) =\u003e\n      _$SecurityAndAnalysisFromJson(json);\n\n  Map\u003cString, dynamic\u003e toJson() =\u003e _$SecurityAndAnalysisToJson(this);\n\n  factory SecurityAndAnalysis.emptyInstance() =\u003e\n      SecurityAndAnalysis(advancedSecurity: AdvancedSecurity.emptyInstance(),\n          secretScanning: SecretScanning.emptyInstance(),\n          secretScanningPushProtection: SecretScanningPushProtection.emptyInstance());\n\n  @override\n  List\u003cObject?\u003e get props =\u003e _$props;\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilinz%2Fjson5_model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilinz%2Fjson5_model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilinz%2Fjson5_model/lists"}