{"id":13413257,"url":"https://github.com/elgs/gojq","last_synced_at":"2025-03-14T19:31:47.616Z","repository":{"id":56215646,"uuid":"48792170","full_name":"elgs/gojq","owner":"elgs","description":"JSON query in Golang","archived":false,"fork":false,"pushed_at":"2023-06-28T21:48:30.000Z","size":16,"stargazers_count":191,"open_issues_count":1,"forks_count":23,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-25T05:25:43.477Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elgs.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}},"created_at":"2015-12-30T09:02:13.000Z","updated_at":"2024-09-06T13:51:40.000Z","dependencies_parsed_at":"2024-01-08T15:34:41.736Z","dependency_job_id":null,"html_url":"https://github.com/elgs/gojq","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/elgs%2Fgojq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgs%2Fgojq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgs%2Fgojq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgs%2Fgojq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elgs","download_url":"https://codeload.github.com/elgs/gojq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243635328,"owners_count":20322921,"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":[],"created_at":"2024-07-30T20:01:36.241Z","updated_at":"2025-03-14T19:31:47.321Z","avatar_url":"https://github.com/elgs.png","language":"Go","funding_links":[],"categories":["Misc","工具库","Utilities","Relational Databases","Go","实用工具","JSON"],"sub_categories":["交流","Advanced Console UIs","Search and Analytic Databases","检索及分析资料库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","SQL 查询语句构建库","HTTP Clients"],"readme":"# gojq\nJSON query in Golang.\n\n## Install\n`go get -u github.com/elgs/gojq`\n\nThis library serves three purposes:\n\n* makes parsing JSON configuration file much easier\n* enables JSON expression evaluation\n* reduces the pain of type assertion parsing JSON \n\n\n## Query from JSON Object\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/elgs/gojq\"\n)\n\nvar jsonObj = `\n{\n  \"name\": \"sam\",\n  \"gender\": \"m\",\n  \"pet\": null,\n  \"skills\": [\n    \"Eating\",\n    \"Sleeping\",\n    \"Crawling\"\n  ],\n  \"hello.world\":true\n}\n`\n\nfunc main() {\n\tparser, err := gojq.NewStringQuery(jsonObj)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tfmt.Println(parser.Query(\"name\"))          // sam \u003cnil\u003e\n\tfmt.Println(parser.Query(\"gender\"))        // m \u003cnil\u003e\n\tfmt.Println(parser.Query(\"skills.[1]\"))    // Sleeping \u003cnil\u003e\n\tfmt.Println(parser.Query(\"hello\"))         // \u003cnil\u003e hello does not exist.\n\tfmt.Println(parser.Query(\"pet\"))           // \u003cnil\u003e \u003cnil\u003e\n\tfmt.Println(parser.Query(\".\"))             // map[name:sam gender:m pet:\u003cnil\u003e skills:[Eating Sleeping Crawling] hello.world:true] \u003cnil\u003e\n\tfmt.Println(parser.Query(\"'hello.world'\")) // true \u003cnil\u003e\n}\n\n```\n\n## Query from JSON Array\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/elgs/gojq\"\n)\n\nvar jsonArray = `\n[\n  {\n    \"name\": \"elgs\",\n    \"gender\": \"m\",\n    \"skills\": [\n      \"Golang\",\n      \"Java\",\n      \"C\"\n    ]\n  },\n  {\n    \"name\": \"enny\",\n    \"gender\": \"f\",\n    \"skills\": [\n      \"IC\",\n      \"Electric design\",\n      \"Verification\"\n    ]\n  },\n  {\n    \"name\": \"sam\",\n    \"gender\": \"m\",\n\t\"pet\": null,\n    \"skills\": [\n      \"Eating\",\n      \"Sleeping\",\n      \"Crawling\"\n    ]\n  }\n]\n`\n\nfunc main() {\n\tparser, err := gojq.NewStringQuery(jsonArray)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tfmt.Println(parser.Query(\"[0].name\"))       // elgs \u003cnil\u003e\n\tfmt.Println(parser.Query(\"[1].gender\"))     // f \u003cnil\u003e\n\tfmt.Println(parser.Query(\"[2].skills.[1]\")) // Sleeping \u003cnil\u003e\n\tfmt.Println(parser.Query(\"[2].hello\"))      // \u003cnil\u003e hello does not exist.\n\tfmt.Println(parser.Query(\"[2].pet\"))        // \u003cnil\u003e \u003cnil\u003e\n}\n```\n## Nested Query\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/elgs/gojq\"\n)\n\nvar jsonArray = `\n[\n  {\n    \"name\": \"elgs\",\n    \"gender\": \"m\",\n    \"skills\": [\n      \"Golang\",\n      \"Java\",\n      \"C\"\n    ]\n  },\n  {\n    \"name\": \"enny\",\n    \"gender\": \"f\",\n    \"skills\": [\n      \"IC\",\n      \"Electric design\",\n      \"Verification\"\n    ]\n  },\n  {\n    \"name\": \"sam\",\n    \"gender\": \"m\",\n\t\"pet\": null,\n    \"skills\": [\n      \"Eating\",\n      \"Sleeping\",\n      \"Crawling\"\n    ]\n  }\n]\n`\n\nfunc main() {\n\tparser, err := gojq.NewStringQuery(jsonArray)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tsamSkills, err := parser.Query(\"[2].skills\")\n\tfmt.Println(samSkills, err) //[Eating Sleeping Crawling] \u003cnil\u003e\n\tsamSkillParser := gojq.NewQuery(samSkills)\n\tfmt.Println(samSkillParser.Query(\"[1]\")) //Sleeping \u003cnil\u003e\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felgs%2Fgojq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felgs%2Fgojq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felgs%2Fgojq/lists"}