{"id":13396830,"url":"https://github.com/stretchr/objx","last_synced_at":"2025-05-12T15:24:13.013Z","repository":{"id":10542589,"uuid":"12738843","full_name":"stretchr/objx","owner":"stretchr","description":"Go package for dealing with maps, slices, JSON and other data.","archived":false,"fork":false,"pushed_at":"2025-02-09T05:41:03.000Z","size":525,"stargazers_count":747,"open_issues_count":7,"forks_count":79,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-12T15:24:10.602Z","etag":null,"topics":["go","golang","objx"],"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/stretchr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"security.go","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-10T19:45:41.000Z","updated_at":"2025-05-07T13:43:48.000Z","dependencies_parsed_at":"2024-06-18T11:16:10.716Z","dependency_job_id":"4c90d87a-bacc-49be-83ff-1e81dc308f7e","html_url":"https://github.com/stretchr/objx","commit_stats":{"total_commits":197,"total_committers":19,"mean_commits":"10.368421052631579","dds":0.6091370558375635,"last_synced_commit":"57832dc6e27fd96037781d1737abf48c4e1edba0"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stretchr%2Fobjx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stretchr%2Fobjx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stretchr%2Fobjx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stretchr%2Fobjx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stretchr","download_url":"https://codeload.github.com/stretchr/objx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253764165,"owners_count":21960524,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","objx"],"created_at":"2024-07-30T18:01:04.020Z","updated_at":"2025-05-12T15:24:12.989Z","avatar_url":"https://github.com/stretchr.png","language":"Go","funding_links":[],"categories":["Go","Library","开源类库","Tool-kits \u0026 helpers","Open source library"],"sub_categories":["序列化","Serialization"],"readme":"# Objx\n[![Build Status](https://travis-ci.org/stretchr/objx.svg?branch=master)](https://travis-ci.org/stretchr/objx)\n[![Go Report Card](https://goreportcard.com/badge/github.com/stretchr/objx)](https://goreportcard.com/report/github.com/stretchr/objx)\n[![Maintainability](https://api.codeclimate.com/v1/badges/1d64bc6c8474c2074f2b/maintainability)](https://codeclimate.com/github/stretchr/objx/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/1d64bc6c8474c2074f2b/test_coverage)](https://codeclimate.com/github/stretchr/objx/test_coverage)\n[![Sourcegraph](https://sourcegraph.com/github.com/stretchr/objx/-/badge.svg)](https://sourcegraph.com/github.com/stretchr/objx)\n[![GoDoc](https://pkg.go.dev/badge/github.com/stretchr/objx?utm_source=godoc)](https://pkg.go.dev/github.com/stretchr/objx)\n\nObjx - Go package for dealing with maps, slices, JSON and other data.\n\nGet started:\n\n- Install Objx with [one line of code](#installation), or [update it with another](#staying-up-to-date)\n- Check out the API Documentation http://pkg.go.dev/github.com/stretchr/objx\n\n## Overview\nObjx provides the `objx.Map` type, which is a `map[string]interface{}` that exposes a powerful `Get` method (among others) that allows you to easily and quickly get access to data within the map, without having to worry too much about type assertions, missing data, default values etc.\n\n### Pattern\nObjx uses a predictable pattern to make access data from within `map[string]interface{}` easy. Call one of the `objx.` functions to create your `objx.Map` to get going:\n\n```go\nm, err := objx.FromJSON(json)\n```\n\nNOTE: Any methods or functions with the `Must` prefix will panic if something goes wrong, the rest will be optimistic and try to figure things out without panicking.\n\nUse `Get` to access the value you're interested in.  You can use dot and array\nnotation too:\n\n```go\nm.Get(\"places[0].latlng\")\n```\n\nOnce you have sought the `Value` you're interested in, you can use the `Is*` methods to determine its type.\n\n```go\nif m.Get(\"code\").IsStr() { // Your code... }\n```\n\nOr you can just assume the type, and use one of the strong type methods to extract the real value:\n\n```go\nm.Get(\"code\").Int()\n```\n\nIf there's no value there (or if it's the wrong type) then a default value will be returned, or you can be explicit about the default value.\n\n```go\nGet(\"code\").Int(-1)\n```\nIf you're dealing with a slice of data as a value, Objx provides many useful methods for iterating, manipulating and selecting that data.  You can find out more by exploring the index below.\n\n### Reading data\nA simple example of how to use Objx:\n\n```go\n// Use MustFromJSON to make an objx.Map from some JSON\nm := objx.MustFromJSON(`{\"name\": \"Mat\", \"age\": 30}`)\n\n// Get the details\nname := m.Get(\"name\").Str()\nage := m.Get(\"age\").Int()\n\n// Get their nickname (or use their name if they don't have one)\nnickname := m.Get(\"nickname\").Str(name)\n```\n\n### Ranging\nSince `objx.Map` is a `map[string]interface{}` you can treat it as such.  For example, to `range` the data, do what you would expect:\n\n```go\nm := objx.MustFromJSON(json)\nfor key, value := range m {\n  // Your code...\n}\n```\n\n## Installation\nTo install Objx, use go get:\n\n    go get github.com/stretchr/objx\n\n### Staying up to date\nTo update Objx to the latest version, run:\n\n    go get -u github.com/stretchr/objx\n\n### Supported go versions\nWe currently support the three recent major Go versions.\n\n## Contributing\nPlease feel free to submit issues, fork the repository and send pull requests!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstretchr%2Fobjx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstretchr%2Fobjx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstretchr%2Fobjx/lists"}