{"id":38756228,"url":"https://github.com/haifenghuang/orderedmap","last_synced_at":"2026-01-17T11:53:42.853Z","repository":{"id":61839598,"uuid":"142543560","full_name":"haifenghuang/orderedmap","owner":"haifenghuang","description":"OrderedMap for go which support marshaling/unmarshaling(using json.Decoder).","archived":false,"fork":false,"pushed_at":"2021-02-04T05:39:41.000Z","size":11,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-21T09:59:46.580Z","etag":null,"topics":["golang","map","marshaling","ordereddict","orderedmap","unmarshalling"],"latest_commit_sha":null,"homepage":"","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/haifenghuang.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":"2018-07-27T07:27:53.000Z","updated_at":"2025-03-03T10:58:14.000Z","dependencies_parsed_at":"2022-10-22T05:00:29.987Z","dependency_job_id":null,"html_url":"https://github.com/haifenghuang/orderedmap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/haifenghuang/orderedmap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haifenghuang%2Forderedmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haifenghuang%2Forderedmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haifenghuang%2Forderedmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haifenghuang%2Forderedmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haifenghuang","download_url":"https://codeload.github.com/haifenghuang/orderedmap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haifenghuang%2Forderedmap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28508462,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T11:50:55.898Z","status":"ssl_error","status_checked_at":"2026-01-17T11:50:55.569Z","response_time":85,"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","map","marshaling","ordereddict","orderedmap","unmarshalling"],"created_at":"2026-01-17T11:53:42.734Z","updated_at":"2026-01-17T11:53:42.830Z","avatar_url":"https://github.com/haifenghuang.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OrderedMap\n\nChinese version: [中文](README_cn.md)\n\n# Summary\n\nOrderedMap is a map which preserving the key order as they are added to the map.\n\n# Feature\n\n* Simple\n* Fast(Use `json.Decoder` for unmarshaling)\n* Powerful API\n* Well documented\n* Marshaling \u0026 UnMarshaling support.\n\n\n# Usage\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"encoding/json\"\n    \"github.com/haifenghuang/orderedmap\"\n)\n\nfunc main() {\n    om := orderedmap.New()\n    om.Set(\"Name\", \"HuangHaiFeng\")\n    om.Set(\"Sex\", \"Male\")\n    om.Set(\"Hobby\", \"Programming\")\n    om.Set(\"Country\", \"China\")\n\n    hobby, _ := om.Get(\"Hobby\")\n    fmt.Printf(\"Hobby = %s\\n\", hobby)\n\n    sex, _ := om.GetAt(1)\n    fmt.Printf(\"sex = %v\\n\", sex)\n\n    om.SetAt(2, \"Married\", true)\n    married, _ := om.GetAt(2)\n    fmt.Printf(\"married = %t\\n\", married)\n\n    fmt.Printf(\"=============================\\n\")\n    fmt.Printf(\"keys = %v\\n\", om.Keys())\n    fmt.Printf(\"values = %v\\n\", om.Values())\n    fmt.Printf(\"mapLen = %d\\n\", om.Len())\n\n    fmt.Printf(\"=============================\\n\")\n    om.DeleteAt(2)\n    fmt.Printf(\"OrderedMap = %s\\n\", om)\n\n    fmt.Printf(\"=============================\\n\")\n    has := om.Exists(\"Married\")\n    fmt.Printf(\"Married? - %t\\n\", has)\n    has = om.Exists(\"Country\")\n    fmt.Printf(\"Country? - %t\\n\", has)\n\n    fmt.Printf(\"=============================\\n\")\n    idx := om.Index(\"Hobby\")\n    fmt.Printf(\"Hobby key's index = %d\\n\", idx)\n\n    fmt.Printf(\"=============================\\n\")\n    b, _ := json.MarshalIndent(om, \"\", \"    \")\n    fmt.Printf(\"Marshal result = %s\\n\", string(b))\n\n    fmt.Printf(\"=============================\\n\")\n    jsonStream := `{\n    \"Name\": \"HuangHaiFeng\",\n    \"Sex\": \"Male\",\n    \"Hobby\": \"Programming\",\n    \"Country\": \"China\"\n}`\n    om2 := orderedmap.New()\n    _ = json.Unmarshal([]byte(jsonStream), om2)\n    fmt.Printf(\"om2 = %v\\n\", om2)\n\n    om2.Sort()\n    fmt.Printf(\"==============================\\n\")\n    fmt.Printf(\"om2 = %v\\n\", om2)\n\n    om3 := om2.Reverse()\n    fmt.Printf(\"==============================\\n\")\n    fmt.Printf(\"om3 = %v\\n\", om3)\n\n    om4 := om3.Filter(func(key string,value interface{}) bool {\n        return key == \"China\" || key == \"Male\"\n    })\n    fmt.Printf(\"==============================\\n\")\n    fmt.Printf(\"om4 = %v\\n\", om4)\n}\n```\n\n# Limitation\n\n* OrderedMap only takes strings for the key.\n* OrderedMap is not thread-safe for concurrent use.(It is simple enough to add one using sync.RWMutex)\n\n# API\n\n| Function | Description |\n| -------- | ----------- |\n| New()  | New create a new OrderedMap. |\n| Get(key string)  | Get returns the value of the map based on its key. |\n| GetAt(pos int)   | GetAt returns the value based on the provided pos. |\n| Set(key string, value interface{}) | Set sets the key/value of the map based on key and value. |\n| SetAt(index int, key string, val interface{}) | SetAt sets the given key to the given value at the specified index. |\n| Delete(key string) | Delete remove an item from the map by the supplied key. |\n| DeleteAt(offset int) | DeleteAt delete the key/value pair from the map by the supplied offset. |\n| Keys()| Keys return the keys of the map in the order they were added. |\n| Values() | Values returns a slice of the values in the order they were added. |\n| Exists(key string) | Exists test whether the key exists or not. |\n| Index(key string) | Index returns the offset of the key in the ordered map. |\n| Len() | Len returns the length of the map. |\n| String() | String returns the JSON serialized string representation. |\n| Reverse() | Reverse reverse key \u0026 value of a map. The value must be a string. |\n| Sort() | Sort the given OrderedMap. |\n| Filter(f func(key string, value interface{}) bool) | Filter an OrderedMap if the provided function return true. |\n| MarshalJSON() ([]byte, error) | MarshalJSON implements the `json.Marshaller` interface. |\n| UnmarshalJSON(b []byte) error| UnmarshalJSON implements the `json.Unmarshaller` interface. |\n\n# Alternatives\n\n* [cevaris/ordered_map](https://github.com/cevaris/ordered_map)\nNot support marshaling/unmarshaling.\n\n* [iancoleman/orderedmap](https://github.com/iancoleman/orderedmap)\nUnmarshaling is self-written, not using `json.Decoder`.\n\n# License\n\nMIT\n\n# Remarks\n\nIf you like this repo，please star \u0026 fork. Thanks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaifenghuang%2Forderedmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaifenghuang%2Forderedmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaifenghuang%2Forderedmap/lists"}