{"id":37125629,"url":"https://github.com/etecs-ru/typedjson","last_synced_at":"2026-01-14T14:31:28.570Z","repository":{"id":79255092,"uuid":"266952110","full_name":"etecs-ru/typedjson","owner":"etecs-ru","description":"go generation for typed marshaling to json","archived":false,"fork":false,"pushed_at":"2020-09-23T19:20:03.000Z","size":21,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-06-20T09:21:31.600Z","etag":null,"topics":["go","golang","json","marshalling","type"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/etecs-ru.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-26T05:26:01.000Z","updated_at":"2022-08-08T04:46:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"90d4ff94-4687-4138-9659-84e8a52e27b7","html_url":"https://github.com/etecs-ru/typedjson","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/etecs-ru/typedjson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etecs-ru%2Ftypedjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etecs-ru%2Ftypedjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etecs-ru%2Ftypedjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etecs-ru%2Ftypedjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/etecs-ru","download_url":"https://codeload.github.com/etecs-ru/typedjson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etecs-ru%2Ftypedjson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28423297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","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":["go","golang","json","marshalling","type"],"created_at":"2026-01-14T14:31:27.823Z","updated_at":"2026-01-14T14:31:28.560Z","avatar_url":"https://github.com/etecs-ru.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typedjson\n\nThis is a code generator for Go that alleviates JSON marshaling/unmarshaling unrelated structs in typed fashion.\n\nImagine, that you send or receive a JSON object with some key `config`. \nThe value of this field can correspond to two structs of your Go program: `FooConfig` and `BarConfig`.\nSo, the field `Config` in your struct must be able to hold a value of two possible types.\nIn this case, you have the following options:\n\n1. You can declare field `Config` as `interface{}` and somehow determine what type you should expect, assign an object of this type to `Config` \nand then unmarshal object.\n1. You can unmarshal field `Config` separately.\n1. You can implement custom `MarshalJSON`/`UnmarshalJSON` for the third type that automatically will handle these cases.\n\nThis package provides means to generate all boilerplate code for the third case.\n\n## Usage\n\n```sh\ntypedjson [OPTION] NAME...\n```\n\nOptions:\n\n* `-interface` string\n\n\tName of the interface that encompass all types.\n\n* `-output` string\n\n\tOutput path where generated code should be saved.\n\n* `-package` string\n\n\tPackage name in generated file (default to GOPACKAGE).\n\n* `-typed` string\n\n\tThe name of the struct that will be used for typed interface (default to `{{interface}}{{Typed}}`).\n\nEach name in position argument should be the name of the struct. \nYou can set an alias for struct name like this: `foo=*FooConfig`.\n\n## Example\n\nFor example, you have two structs:\n\n```go\ntype FooConfig struct {\n\tFoo int\n}\n\ntype BarConfig struct {\n\tBar string\n}\n```\n\nThen you must declare an interface that will hold either of these structs.\nThe interface must have the method `TypedJSON` with a special signature. \nThis method will advise compiler to work with types.\n\n```go\n//go:generate go run github.com/etecs-ru/typedjson -interface Config *FooConfig *BarConfig\ntype Config interface {\n\tTypedJSON(*ConfigTyped) string\n}\n```\n\nAfter this, run `go generate`. \nGenerated struct `ConfigTyped` will have special implemented methods `MarshalJSON`/`UnmarshalJSON`.\nYou can use generated code like this:\n\n```go\ntype MyObject struct {\n\tName string `json:\"name\"`\n\tConfigTyped ConfigTyped `json:\"config\"`\n}\n\nfunc main() {\n\tjsonSources := []byte(`\n\t{\n\t\t\"name\": \"my name\",\n\t\t\"config\": {\n\t\t\t\"T\": \"*FooConfig\",\n\t\t\t\"V\": {\n\t\t\t\t\"Foo\": 123\n\t\t\t}\n\t\t}\n\t}`)\n\tvar object MyObject\n\tif err := json.Unmarshal(jsonSources, \u0026object); err != nil {\n\t\tpanic(err)\n\t}\n\tfooConfig := object.ConfigTyped.Config.(*FooConfig)\n\tif fooConfig.Foo != 123 {\n\t\tpanic(\"fail\")\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetecs-ru%2Ftypedjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fetecs-ru%2Ftypedjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetecs-ru%2Ftypedjson/lists"}