{"id":15320241,"url":"https://github.com/alimy/tson","last_synced_at":"2026-04-16T11:03:32.073Z","repository":{"id":89528451,"uuid":"167138272","full_name":"alimy/tson","owner":"alimy","description":"Simple JSON content merge.","archived":false,"fork":false,"pushed_at":"2019-01-24T03:01:39.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-16T11:16:11.164Z","etag":null,"topics":["go","json","template"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alimy.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":"2019-01-23T07:31:39.000Z","updated_at":"2019-01-24T03:01:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"2132b676-3b5f-4c0d-82e3-3e7109124ee8","html_url":"https://github.com/alimy/tson","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"b8105faf744715c6990b0534e598ec8b99f64453"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alimy/tson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Ftson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Ftson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Ftson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Ftson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alimy","download_url":"https://codeload.github.com/alimy/tson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alimy%2Ftson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31882886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T09:23:21.276Z","status":"ssl_error","status_checked_at":"2026-04-16T09:23:15.028Z","response_time":69,"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":["go","json","template"],"created_at":"2024-10-01T09:08:00.714Z","updated_at":"2026-04-16T11:03:32.057Z","avatar_url":"https://github.com/alimy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tson\nTson used to merge JSON content from a json template and a struct type object instance.\n\n#### Prototype\n1. Use `tson` that defined in struct's tag string to tag json template info help tson to merge content from struct type object \n2. Or use `$.filedNanme` that defined in json template string help tson to merge content from struct type object\n3. tson `Parse(...)/ParseFrom(...)` will build a AST tree that contain json segment content\n4. tson use parsed `AST` tree merge give struct type object instance content then write result to target io.Writer\n5. json template can cached in memory or key-value storage such as Redis\n\n#### Usage\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"github.com/alimy/tson\"\n)\n\ntype Issue struct {\n\tVersion string `json:\"version\"`\n\tBio     string `json:\"bio\"`\n}\n\ntype Data struct {\n\tId     string `json:\"id\" tson:\"id\"`\n\tName   string `json:\"name\" tson:\"name\"`\n\tAge    uint8  `json:\"age\" tson:\"age\"`\n\tIssue  *Issue `json:\"issue\"`\n\tRandom []int  `json:\"random\"`\n}\n\ntype Info struct {\n\tName  string\n\tAlias string\n}\n\nfunc main() {\n\t// merge json content from struct type template\n\tsrcData := \u0026Data{\n\t\tAge: 0,\n\t\tIssue: \u0026Issue{\n\t\t\tVersion: \"v0.1.0\",\n\t\t\tBio:     \"happy in codding\",\n\t\t},\n\t\tRandom: []int{1, 2, 3, 4, 5},\n\t}\n\tif jsonTmpl, err := tson.New(\"json\").Parse(srcData); err == nil {\n\t\tbuf := bytes.NewBuffer([1024]byte{}[:])\n\t\tjsonTmpl.Execute(buf, \u0026Data{\n\t\t\tId:   \"1006013\",\n\t\t\tName: \"Michael Li\",\n\t\t})\n\t\tfmt.Println(buf.String())\n\t}\n\n\t// merge json content from text string template\n\tjsonTmplStr := `{\n            \"name\": $.Name,\n            \"alias\": $.Alias,\n            \"other\": {\n                \"ping\": \"pong\",\n       \t    },\n    \t}`\n\tif jsonTmpl, err := tson.New(\"tson\").ParseFrom(jsonTmplStr); err == nil {\n\t\tbuf := bytes.NewBuffer([1024]byte{}[:])\n\t\tjsonTmpl.Execute(buf, \u0026Info{\n\t\t\tName:  \"Micheal Li\",\n\t\t\tAlias: \"Alimy\",\n\t\t})\n\t\tfmt.Println(buf.String())\n\t}\n}\n// Output:\n//  {\n//      \"id\": \"1006013\",\n//      \"name\": \"Michael Li\",\n//      \"age\": 0,\n//      \"issue\": {\n//          \"version\": \"v0.1.0\",\n//          \"bio\": \"happy in codding\",\n//      },\n//      \"random\": [1, 2, 3, 4, 5],\n//  }\n//  {\n//      \"name\": \"Micheal Li\",\n//      \"alias\": \"Alimy\",\n//      \"other\": {\n//          \"ping\": \"pong\",\n//      },\n//  }\n\n```\n\n#### Status\nProject is just a prototype now will add logic implements later.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falimy%2Ftson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falimy%2Ftson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falimy%2Ftson/lists"}