{"id":21578586,"url":"https://github.com/guidao/jsonquery","last_synced_at":"2026-05-15T08:03:00.014Z","repository":{"id":151183301,"uuid":"131283049","full_name":"guidao/jsonquery","owner":"guidao","description":"another way to access json for go","archived":false,"fork":false,"pushed_at":"2019-04-08T12:32:23.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T14:17:51.383Z","etag":null,"topics":["golang","json"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guidao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-04-27T10:37:44.000Z","updated_at":"2019-04-08T12:32:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"26f6027b-6b82-4527-a151-e1c4f573221e","html_url":"https://github.com/guidao/jsonquery","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidao%2Fjsonquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidao%2Fjsonquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidao%2Fjsonquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidao%2Fjsonquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guidao","download_url":"https://codeload.github.com/guidao/jsonquery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244177667,"owners_count":20410997,"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":["golang","json"],"created_at":"2024-11-24T13:11:04.293Z","updated_at":"2026-05-15T08:02:54.981Z","avatar_url":"https://github.com/guidao.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# jsonquery\n一个方便的json值获取库, go的json解析方式要么需要预先定义结构，要么需要处理map[string]interface{}。第一种取值方便，解析麻烦。第二种解析时方便，取值时麻烦。而这个库综合了这两种方式的优点。\n\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\tjq \"github.com/guidao/jsonquery\"\n)\n\nfunc main() {\n\t//error\n\tv := jq.NewLens().Key(\"inner\").GetWithJson(`{}`)\n\tfmt.Println(v.StringOr(\"default\"), v.Error())\n\n\t//object\n\thello := jq.NewLens().Key(\"hello\").GetWithJson(`{\"hello\": \"world\"}`).StringOr(\"\")\n\tfmt.Println(hello) // world\n\n\t//array\n\tf23, err := jq.NewLens().Key(\"array\").Index(2).GetWithJson(`{\"array\":[\"hello\", \"world\", 23]}`).Float64()\n\tfmt.Println(f23, err) //23, nil\n\n\t//foreach\n\terr = jq.NewLens().Key(\"array\").GetWithJson(`{\"array\":[\"hello\", \"world\", 23]}`).ForeachArray(func(i int, v jq.Value) {\n\t\tfmt.Printf(\"i:%v, v:%v\\n\", i, v.InterfaceOr(nil))\n\t\t// i:0, v:hello\n\t\t// i:1, v:world\n\t\t// i:2, v:23\n\t})\n\tfmt.Println(err) //nil\n}\n\n```\n\n更多例子参考test文件\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguidao%2Fjsonquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguidao%2Fjsonquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguidao%2Fjsonquery/lists"}