{"id":19904633,"url":"https://github.com/nixzhu/baby","last_synced_at":"2026-03-07T11:04:17.810Z","repository":{"id":63919303,"uuid":"88570448","full_name":"nixzhu/Baby","owner":"nixzhu","description":"Create models from a JSON file, even a Baby can do it.","archived":false,"fork":false,"pushed_at":"2021-11-18T02:37:57.000Z","size":114,"stargazers_count":222,"open_issues_count":6,"forks_count":21,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-10T16:56:17.874Z","etag":null,"topics":["code-generator","json","model","parser","parser-combinators","swift"],"latest_commit_sha":null,"homepage":"https://apps.apple.com/cn/app/ducky-model-editor/id1525505933","language":"Swift","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/nixzhu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-18T02:06:06.000Z","updated_at":"2024-04-25T09:10:51.000Z","dependencies_parsed_at":"2023-01-14T14:00:49.059Z","dependency_job_id":null,"html_url":"https://github.com/nixzhu/Baby","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixzhu%2FBaby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixzhu%2FBaby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixzhu%2FBaby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixzhu%2FBaby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nixzhu","download_url":"https://codeload.github.com/nixzhu/Baby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253450206,"owners_count":21910511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["code-generator","json","model","parser","parser-combinators","swift"],"created_at":"2024-11-12T20:29:07.467Z","updated_at":"2026-03-07T11:04:12.766Z","avatar_url":"https://github.com/nixzhu.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Baby\n\nCreate models from a JSON file, even a Baby can do it.\n\n## Description\n\nBaby can infer property's type from json such as `String`, `Int`, `Double`, `URL` and `Date`.\n\nBaby can handle nested json, it will generate nested models.\n\nBaby supports `Codable` from Swift 4.\n\n### Example\n\nJSON:\n\n``` json\n{\n    \"id\": 42,\n    \"name\": \"nixzhu\",\n    \"twitter\": {\n        \"profile_url\": \"https://twitter.com/nixzhu\",\n        \"created_at\": \"2009-05-12T10:25:43.511Z\"\n    }\n}\n```\n\nSwift code with `Codable`:\n\n``` swift\nstruct User: Codable {\n    let id: Int\n    let name: String\n    struct Twitter: Codable {\n        let profileURL: URL\n        let createdAt: Date\n        private enum CodingKeys: String, CodingKey {\n            case profileURL = \"profile_url\"\n            case createdAt = \"created_at\"\n        }\n    }\n    let twitter: Twitter\n}\n```\n\nNote that there use **Property Map** `profile_url: profileURL` to change the property name (Automatically generated will be `profileUrl`).\n\nSwift code without `Codable`:\n\n``` swift\nstruct User {\n    let id: Int\n    let name: String\n    struct Twitter {\n        let profileURL: URL\n        let createdAt: Date\n        init(profileURL: URL, createdAt: Date) {\n            self.profileURL = profileURL\n            self.createdAt = createdAt\n        }\n        init?(json: [String: Any]) {\n            guard let profileURLString = json[\"profile_url\"] as? String else { return nil }\n            guard let profileURL = URL(string: profileURLString) else { return nil }\n            guard let createdAtString = json[\"created_at\"] as? String else { return nil }\n            guard let createdAt = DateFormatter.iso8601.date(from: createdAtString) else { return nil }\n            self.init(profileURL: profileURL, createdAt: createdAt)\n        }\n    }\n    let twitter: Twitter\n    init(id: Int, name: String, twitter: Twitter) {\n        self.id = id\n        self.name = name\n        self.twitter = twitter\n    }\n    init?(json: [String: Any]) {\n        guard let id = json[\"id\"] as? Int else { return nil }\n        guard let name = json[\"name\"] as? String else { return nil }\n        guard let twitterJSONDictionary = json[\"twitter\"] as? [String: Any] else { return nil }\n        guard let twitter = Twitter(json: twitterJSONDictionary) else { return nil }\n        self.init(id: id, name: name, twitter: twitter)\n    }\n}\n```\n\nYou may need a `DateFormatter` extension:\n\n``` swift\nextension DateFormatter {\n\n    static let iso8601: DateFormatter = {\n        let formatter = DateFormatter()\n        formatter.timeZone = TimeZone(abbreviation: \"UTC\")\n        formatter.locale = Locale(identifier: \"en_US_POSIX\")\n        formatter.dateFormat = \"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ\"\n        return formatter\n    }()\n}\n```\n\nBaby can also handle array root json, it will automatically merge properties for objects in array.\n\n## Installation\n\n### Build\n\n```bash\n$ bash install.sh\n```\n\n### Run\n\n``` bash\n$ baby -i JSONFilePath\n```\n\n### Help\n\n``` bash\n$ baby --help\n```\n\nTry Baby's web interface [SharedBaby](https://github.com/nixzhu/SharedBaby) if you like.\n\nGet [Ducky](https://apps.apple.com/cn/app/ducky-model-editor/id1525505933) in the Mac App Store.\n\n## Contact\n\nYou can find me on [Twitter](https://twitter.com/nixzhu).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixzhu%2Fbaby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnixzhu%2Fbaby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixzhu%2Fbaby/lists"}