{"id":42914123,"url":"https://github.com/mixcode/golib-json-snake","last_synced_at":"2026-01-30T17:03:01.960Z","repository":{"id":56859250,"uuid":"374018098","full_name":"mixcode/golib-json-snake","owner":"mixcode","description":"A json encoder/decoder for snake_cased_object_names","archived":false,"fork":false,"pushed_at":"2023-08-09T05:51:45.000Z","size":371,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T13:05:26.454Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mixcode.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":"2021-06-05T04:17:10.000Z","updated_at":"2022-08-19T06:15:39.000Z","dependencies_parsed_at":"2024-06-21T12:07:15.256Z","dependency_job_id":null,"html_url":"https://github.com/mixcode/golib-json-snake","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"38c9e1ce87c00181bb6cbaaf6e9996655a4387fe"},"previous_names":["mixcode/golib-json"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/mixcode/golib-json-snake","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixcode%2Fgolib-json-snake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixcode%2Fgolib-json-snake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixcode%2Fgolib-json-snake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixcode%2Fgolib-json-snake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mixcode","download_url":"https://codeload.github.com/mixcode/golib-json-snake/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixcode%2Fgolib-json-snake/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28915942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T16:37:38.804Z","status":"ssl_error","status_checked_at":"2026-01-30T16:37:37.878Z","response_time":66,"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":[],"created_at":"2026-01-30T17:02:53.810Z","updated_at":"2026-01-30T17:03:01.945Z","avatar_url":"https://github.com/mixcode.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# golib-json\n\nA modified go \"encoding/json\" package that may writes struct field names in _snake\\_case_,  _lowerCamelCase_, and _lowercase_.\n\n## Snake-cased marshaling and unmarshalling.\n\nThis package is almost-compatible with Go standard encoding/json package, except for a few additional functions.\nMost important functions added are `MarshalSnakeCase()` and `UnmarshalSnakeCase()`. As the name implies, `MarshalSnakeCase()` converts Go's _CamelCase_ named members to _snake\\_case_ named JSON field members. `UnmarshalSnakeCase()` is vice versa.\n\n\n## lowerCamelCase / lowercased marshalling/unmarshalling\n\nfunction `MarshalLowerCamelCase()` and `UnmarshalLowerCamelCase()` handles JSON field names in lowerCamelCase, that means each word is capitalized except for the first word.\nAlso, function `MarshalLowerCase()` and `UnmarshalLowerCase()` handles JSON field names in lowercase, that means all words are lowercased and concatenated without spaces.\n\n\n### Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\tjson \"github.com/mixcode/golib-json-snake\"\n)\n\nfunc main() {\n\ttype st struct {\n\t\tName          string // JSON object name will be \"name\"\n\t\tAnotherName   string // JSON object name will be \"another_name\"\n\t\tExplicitCamel string `json:\"ExplicitCamel\"` // If a name tag is explicitly set, the name will be used as-is\n\t\tExplicitSnake string `json:\"explicit_snake\"`\n\t\tEmpty         int\n\t}\n\n\tin := st{\"name\", \"another_name\", \"camel\", \"snake\", 0}\n\n\t// encode with snake case\n\tencoded, err := json.MarshalSnakeCase(\u0026in, false)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(string(encoded))\n\n\t// Output:\n\t// {\"name\":\"name\",\"another_name\":\"another_name\",\"ExplicitCamel\":\"camel\",\"explicit_snake\":\"snake\",\"empty\":0}\n}\n```\n\n## Decoding of pre-set structs in \"map[string]any\" variables\n\nStandard Go encoding/json package can unmarshal any JSON string into `map[string]any` type. In this case, child objects are also unmarshalled to `map[string]any` type.\n\nIn this package, child objects could be unmarshalled into proper structs if they are pre-placed to the map.\n\n\n### Example\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\tjson \"github.com/mixcode/golib-json-snake\"\n)\n\nfunc main() {\n\t// a custom struct\n\ttype myStruct struct {\n\t\tName string\n\t\tYes  bool\n\t}\n\n\tm := make(map[string]any) // A universal map to decode a JSON\n\tm[\"payload\"] = myStruct{} // If we know a exact type of an object, we can pre-set a receiver for the object\n\n\t// the 'payload' member in supplied json will be decoded to myStruct placed at m[\"payload\"]\n\terr := json.UnmarshalSnakeCase([]byte(`{\"ok\":true,\"payload\":{\"name\":\"mixcode\",\"yes\":true}}`), \u0026m)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// print the result\n\tvar p myStruct = m[\"payload\"].(myStruct)\n\tfmt.Printf(\"%v\", p)\n\t// Output:\n\t//{mixcode true}\n}\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmixcode%2Fgolib-json-snake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmixcode%2Fgolib-json-snake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmixcode%2Fgolib-json-snake/lists"}