{"id":42603568,"url":"https://github.com/genelet/determined","last_synced_at":"2026-01-29T01:41:42.815Z","repository":{"id":57693814,"uuid":"485825607","full_name":"genelet/determined","owner":"genelet","description":"Build customized JSON and HCL Unmarshaler with Determined","archived":false,"fork":false,"pushed_at":"2025-12-03T23:04:25.000Z","size":409,"stargazers_count":24,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-04T22:29:56.324Z","etag":null,"topics":["golang","hcl","json"],"latest_commit_sha":null,"homepage":"https://medium.com/@peterbi_91340/decoding-of-dynamic-json-data-1d4e67318661","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/genelet.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-04-26T14:39:13.000Z","updated_at":"2025-12-03T23:03:24.000Z","dependencies_parsed_at":"2023-12-10T11:31:37.166Z","dependency_job_id":"671274ff-67a7-4b23-b87d-281b5c882300","html_url":"https://github.com/genelet/determined","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"purl":"pkg:github/genelet/determined","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genelet%2Fdetermined","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genelet%2Fdetermined/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genelet%2Fdetermined/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genelet%2Fdetermined/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/genelet","download_url":"https://codeload.github.com/genelet/determined/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genelet%2Fdetermined/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28859441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T22:56:21.783Z","status":"ssl_error","status_checked_at":"2026-01-28T22:56:00.861Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["golang","hcl","json"],"created_at":"2026-01-29T01:41:42.186Z","updated_at":"2026-01-29T01:41:42.802Z","avatar_url":"https://github.com/genelet.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# determined\n\n_Determined_ marshals and unmarshals JSON data to _go struct_ containing interfaces determined at run-time.\n\n[![GoDoc](https://godoc.org/github.com/genelet/determined?status.svg)](https://godoc.org/github.com/genelet/determined)\n\n\u003e **Note**: The HCL parsing feature has been extracted and moved to a separate Github package [github.com/genelet/horizon](https://github.com/genelet/horizon). The old HCL code in this package is frozen for compatibility reasons.\n\n## Installation\n\n```bash\ngo get github.com/genelet/determined\n```\n\n## Introduction\n\nThe core Golang package `encoding/json` is an exceptional library for managing JSON data. However, to decode the interface type, it necessitates writing a customized `Unmarshaler` for the target object. While this isn’t typically a challenging task, it often results in repetitive code for different types of objects and packages.\n\nTherefore, `determined` was created to streamline the coding process and enhance productivity.\n\n## Usage\n\nTo decode JSON to an object containing interface types, use `det.JsonUnmarshal`.\n\n```go\n// JsonUnmarshal unmarshals JSON data with interfaces determined by spec.\n//\n//   - dat: JSON data\n//   - current: object as pointer\n//   - spec: *schema.Struct\n//   - ref: struct map, with key being string name and value reference to struct\nfunc JsonUnmarshal(dat []byte, current interface{}, spec *schema.Struct, ref map[string]interface{}) error\n```\n\nYou first need to define the structure of your interfaces using `schema.NewStruct` from the [github.com/genelet/schema](https://github.com/genelet/schema) package.\n\n### Example\n\nHere is an example of how to use `determined` to decode JSON data where fields are interfaces.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/genelet/determined/det\"\n    \"github.com/genelet/schema\"\n)\n\ntype geo struct {\n    Name  string `json:\"name\"`\n    Shape inter  `json:\"shape\"`\n}\n\ntype inter interface {\n    Area() float32\n}\n\ntype square struct {\n    SX int `json:\"sx\"`\n    SY int `json:\"sy\"`\n}\n\nfunc (self *square) Area() float32 {\n    return float32(self.SX * self.SY)\n}\n\ntype circle struct {\n    Radius float32 `json:\"radius\"`\n}\n\nfunc (self *circle) Area() float32 {\n    return 3.14159 * self.Radius\n}\n\ntype toy struct {\n    Geo     geo     `json:\"geo\"`\n    ToyName string  `json:\"toy_name\"`\n    Price   float32 `json:\"price\"`\n}\n\ntype child struct {\n    Brand map[string]*toy `json:\"brand\"`\n    Age   int  `json:\"age\"`\n}\n\nfunc main() {\n    data1 := `{\n        \"age\" : 5,\n        \"brand\" : {\n            \"abc1\" : {\n                \"toy_name\" : \"roblox\",\n                \"price\" : 99.9,\n                \"geo\" : {\n                    \"name\" : \"medium shape\",\n                    \"shape\" : { \"radius\" : 1.234 }\n                }\n            },\n            \"def2\" : {\n                \"toy_name\" : \"minecraft\",\n                \"price\" : 9.9,\n                \"geo\" : {\n                    \"name\" : \"square shape\",\n                    \"shape\" : { \"sx\" : 5, \"sy\" : 6 }\n                }\n            }\n        }\n    }`\n\n    // Define the structure of the interfaces for the specific data\n    spec, err := schema.NewStruct(\n        \"child\", map[string]interface{}{\n            \"Brand\": map[string][2]interface{}{\n                \"abc1\":[2]interface{}{\"toy\", map[string]interface{}{\n                    \"Geo\": [2]interface{}{\n                        \"geo\", map[string]interface{}{\"Shape\": \"circle\"}}}},\n                \"def2\":[2]interface{}{\"toy\", map[string]interface{}{\n                    \"Geo\": [2]interface{}{\n                        \"geo\", map[string]interface{}{\"Shape\": \"square\"}}}},\n            },\n        },\n    )\n    if err != nil {\n        panic(err)\n    }\n\n    // Map string names to actual struct pointers\n    ref := map[string]interface{}{\n        \"toy\": \u0026toy{}, \n        \"geo\": \u0026geo{}, \n        \"circle\": \u0026circle{}, \n        \"square\": \u0026square{},\n    }\n\n    c := new(child)\n    err = det.JsonUnmarshal([]byte(data1), c, spec, ref)\n    if err != nil {\n        panic(err)\n    }\n    \n    fmt.Printf(\"Age: %v\\n\", c.Age)\n    fmt.Printf(\"Brand abc1: %#v\\n\", c.Brand[\"abc1\"])\n    fmt.Printf(\"Brand abc1 Shape: %#v\\n\", c.Brand[\"abc1\"].Geo.Shape)\n    fmt.Printf(\"Brand def2: %#v\\n\", c.Brand[\"def2\"])\n    fmt.Printf(\"Brand def2 Shape: %#v\\n\", c.Brand[\"def2\"].Geo.Shape)\n}\n```\n\nFor more details on how to construct the `spec` using `NewStruct`, please refer to [DOCUMENT.md](DOCUMENT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenelet%2Fdetermined","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenelet%2Fdetermined","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenelet%2Fdetermined/lists"}