{"id":37094795,"url":"https://github.com/zyx4843/gojson","last_synced_at":"2026-01-14T11:40:15.544Z","repository":{"id":57483287,"uuid":"81213588","full_name":"zyx4843/gojson","owner":"zyx4843","description":"gojson是快速解析json数据的一个golang包，你使用它可以快速的查找json内的数据","archived":false,"fork":true,"pushed_at":"2017-02-07T14:32:22.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T12:41:41.979Z","etag":null,"topics":["go","json","json-parser"],"latest_commit_sha":null,"homepage":"http://www.widuu.com/archives/02/965.html","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"widuu/gojson","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zyx4843.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":"2017-02-07T13:56:27.000Z","updated_at":"2022-01-25T02:06:12.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zyx4843/gojson","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zyx4843/gojson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyx4843%2Fgojson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyx4843%2Fgojson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyx4843%2Fgojson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyx4843%2Fgojson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zyx4843","download_url":"https://codeload.github.com/zyx4843/gojson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zyx4843%2Fgojson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419242,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"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","json-parser"],"created_at":"2026-01-14T11:40:14.944Z","updated_at":"2026-01-14T11:40:15.538Z","avatar_url":"https://github.com/zyx4843.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"gojson\n===\n[![Build Status](https://drone.io/github.com/widuu/gojson/status.png)](https://drone.io/github.com/widuu/gojson/latest)\n\n---\n**[The official website](http://www.widuu.com)**\n\n##中文文档\n\n###简介\n\n\u003egojson是快速解析json数据的一个golang包，你使用它可以快速的查找json内的数据\n\n###安装\n\n \t 原作者 go get github.com/widuu/gojson\n \t 修改过的包 go get github.com/zyx4843/gojson\n\n###修改说明\n\t\n\t增加函数IsValid()判断数据是否有效\n\tGetindex防止出现越界\n\tTostring增加bool类型\n\n###使用简介\n\n结构\n\n\ttype Js struct {\n\t\tdata interface{}\n\t}\n\n(1) `func Json(data) *Js` data为string类型,初始化Js结构，解析json并且return `Js.data`\n\n\tjson := `{\"from\":\"en\",\"to\":\"zh\"}`\n\tc1 := gojson.Json(json) //\u0026{map[from:en to:zh]}\n\n(2) `func (*Js) Get() *js` 获取简单json中的某个值，递归查找，return `Js.data`\n\n\tjson := `{\"from\":\"en\",\"to\":\"zh\",\"trans_result\":{\"src\":\"today\",\"dst\":\"\\u4eca\\u5929\"},\"result\":[\"src\",\"today\",\"dst\",\"\\u4eca\\u5929\"]}`\n\t\n \tc2 := gojson.Json(json).Get(\"trans_result\").Get(\"dst\")\n\tfmt.Println(c2) //\u0026{今天}\n\n\tc2 := gojson.Json(json).Get(\"from\")\n\tfmt.Println(c2) //\u0026{en}\n\n(3) `func (*Js)Tostring()string` 将单个数据转化成string类型,因为string类型转其它类型都比较好转就让数据返回string\n\n\tc2 := gojson.Json(json).Get(\"from\").Tostring()\n\tfmt.Println(c2) //en\n\n(4) `func (j *Js) Getpath(args ...string) *Js ` 通过输入string的多个参数来获取某个值，json数据一定要是递归的\n\n \tc4 := gojson.Json(json).Getpath(\"trans_result\", \"src\").Tostring()\n\tfmt.Println(c4)  //today\n\n(5) `func (j *Js) Arrayindex(i int) string` 获取Json数据中数组结构的值，根据输入的num来返回对应的值，仅限于处理{\"result\":[\"src\",\"today\",\"dst\",\"\\u4eca\\u5929\"]}中[]内的值\n\n\tjson := `{\"from\":\"en\",\"to\":\"zh\",\"trans_result\":{\"src\":\"today\",\"dst\":\"\\u4eca\\u5929\"},\"result\":[\"src\",\"today\",\"dst\",\"\\u4eca\\u5929\"]}`\n\tc7 := gojson.Json(json).Get(\"result\").Arrayindex(1)\n\tfmt.Println(c7) //src\n\n(6) `func (j *Js) Getkey(key string, i int) *Js` 这个函数是针对数据中有重复数据，取值，使用js.data必须是[]interface{}类型，这个是百度翻译时候返回的js可能会用到\n\n \tjson1 := `{\"from\":\"en\",\"to\":\"zh\",\"trans_result\":[{\"src\":\"today\",\"dst\":\"\\u4eca\\u5929\"},{\"src\":\"tomorrow\",\"dst\":\"\\u660e\\u5929\"}]}`\n\tc8 := gojson.Json(json1).Get(\"trans_result\").Getkey(\"src\", 1).Tostring()\n\tfmt.Println(c8) //则返回trans_result第一组中的src today\n\n(7) `func (j *Js) ToArray() (k, d []string) `将json数据转换成key []string{} value []string{} 一一对应的数组，只能使用到二级 不能到多级\n\n\t\n \tc9k, c9v := gojson.Json(json1).Get(\"trans_result\").ToArray()\n\tfmt.Println(c9k, c9v) //[src dst src dst] [today 今天 tomorrow 明天]\n\n\tc3k, c3v := gojson.Json(json).Getindex(1).ToArray()\n\tfmt.Println(c3k, c3v) //\t[from] [en]\n\n(8) `func (j *Js) Getindex(i int) *Js ` 根据i返回json内的数据，可以逐级查找\n\n\t\n\tjson1 := `{\"from\":\"en\",\"to\":\"zh\",\"trans_result\":[{\"src\":\"today\",\"dst\":\"\\u4eca\\u5929\"},{\"src\":\"tomorrow\",\"dst\":\"\\u660e\\u5929\"}]}`\n\n\tc10 := gojson.Json(json1).Getindex(3).Getindex(1).Getindex(1).Get(\"src\").Tostring()\n\tfmt.Println(c10) //today\n\n(9) `func (j *Js) StringtoArray() []string` 将{\"result\":[\"src\",\"today\",\"dst\",\"\\u4eca\\u5929\"]}数据json中的result对应的数据，返回成[]string的slice\n\n\tc11 := gojson.Json(json).Get(\"result\").StringtoArray()\n\tfmt.Println(c11) //[src today dst 今天]\n\n(10) `func (j *Js) Type()` 打印测试用，打印数据类型\n\n\tgojson.Json(json).Get(\"result\").Type()  //[]interface {}\n\n---\n\n\n##English Document\n\n###Introduction\n\n\u003egojson是快速解析json数据的一个golang包，你使用它可以快速的查找json内的数据\n\n###Install\n\n \t go get github.com/widuu/gojson\n\n###Use\n\nstructure\n\n\ttype Js struct {\n\t\tdata interface{}\n\t}\n\n(1) `func Json(data) *Js` data is string type,initialize Js structure, parse the json and return `Js.data`\n\n\tjson := `{\"from\":\"en\",\"to\":\"zh\"}`\n\tc1 := gojson.Json(json) //\u0026{map[from:en to:zh]}\n\n(2) `func (*Js) Get() *js` Retrieve a value from a simple json, recursive lookup，return `Js.data`\n\n\tjson := `{\"from\":\"en\",\"to\":\"zh\",\"trans_result\":{\"src\":\"today\",\"dst\":\"\\u4eca\\u5929\"},\"result\":[\"src\",\"today\",\"dst\",\"\\u4eca\\u5929\"]}`\n\t\n \tc2 := gojson.Json(json).Get(\"trans_result\").Get(\"dst\")\n\tfmt.Println(c2) //\u0026{今天}\n\n\tc2 := gojson.Json(json).Get(\"from\")\n\tfmt.Println(c2) //\u0026{en}\n\n(3) `func (*Js)Tostring()string` To a single data into type string, for type string turned other types are better let return to string data\n\n\tc2 := gojson.Json(json).Get(\"from\").Tostring()\n\tfmt.Println(c2) //en\n\n(4) `func (j *Js) Getpath(args ...string) *Js ` Get a value by multiple parameters of the input string, the json data must be recursive\n\n \tc4 := gojson.Json(json).Getpath(\"trans_result\", \"src\").Tostring()\n\tfmt.Println(c4)  //today\n\n(5) `func (j *Js) Arrayindex(i int) string` Get the value of the array structure in the Json data, based on the input of num to return the value of the corresponding is limited to processing {\" result \": [\" SRC\", \"today\", \"DST\", \"\\ u4eca \\ u5929\"]} [] in value\n\n\tjson := `{\"from\":\"en\",\"to\":\"zh\",\"trans_result\":{\"src\":\"today\",\"dst\":\"\\u4eca\\u5929\"},\"result\":[\"src\",\"today\",\"dst\",\"\\u4eca\\u5929\"]}`\n\tc7 := gojson.Json(json).Get(\"result\").Arrayindex(1)\n\tfmt.Println(c7) //src\n\n(6) `func (j *Js) Getkey(key string, i int) *Js` There is duplicate data in this function is for data, the values, use js. Data must be [] interface {} type, this is baidu translation when the returned js might need\n\n \tjson1 := `{\"from\":\"en\",\"to\":\"zh\",\"trans_result\":[{\"src\":\"today\",\"dst\":\"\\u4eca\\u5929\"},{\"src\":\"tomorrow\",\"dst\":\"\\u660e\\u5929\"}]}`\n\tc8 := gojson.Json(json1).Get(\"trans_result\").Getkey(\"src\", 1).Tostring()\n\tfmt.Println(c8) //则返回trans_result第一组中的src today\n\n(7) `func (j *Js) ToArray() (k, d []string) ` Converting the json data into key string [] {} the value string [] {} one-to-one array, can only be used to level 2 not to multistage\n\n\t\n \tc9k, c9v := gojson.Json(json1).Get(\"trans_result\").ToArray()\n\tfmt.Println(c9k, c9v) //[src dst src dst] [today 今天 tomorrow 明天]\n\n\tc3k, c3v := gojson.Json(json).Getindex(1).ToArray()\n\tfmt.Println(c3k, c3v) //\t[from] [en]\n\n(8) `func (j *Js) Getindex(i int) *Js ` According to the I returned in the json data, can find step by step\n\n\t\n\tjson1 := `{\"from\":\"en\",\"to\":\"zh\",\"trans_result\":[{\"src\":\"today\",\"dst\":\"\\u4eca\\u5929\"},{\"src\":\"tomorrow\",\"dst\":\"\\u660e\\u5929\"}]}`\n\n\tc10 := gojson.Json(json1).Getindex(3).Getindex(1).Getindex(1).Get(\"src\").Tostring()\n\tfmt.Println(c10) //today\n\n(9) `func (j *Js) StringtoArray() []string` Will {\" result \":\" SRC \", \"today\", \"DST\", \"\\ u4eca \\ u5929\"]} corresponding data, the result of the json data returned into [] string slice\n\n\tc11 := gojson.Json(json).Get(\"result\").StringtoArray()\n\tfmt.Println(c11) //[src today dst 今天]\n\n(10) `func (j *Js) Type()` Print test, the data type\n\n\tgojson.Json(json).Get(\"result\").Type()  //[]interface {}\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzyx4843%2Fgojson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzyx4843%2Fgojson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzyx4843%2Fgojson/lists"}