{"id":13413271,"url":"https://github.com/abusomani/jsonhandlers","last_synced_at":"2026-03-09T20:32:44.200Z","repository":{"id":131493532,"uuid":"610281457","full_name":"abusomani/jsonhandlers","owner":"abusomani","description":"JSON library to expose simple handlers that lets you easily read and write json from various sources.","archived":false,"fork":false,"pushed_at":"2023-03-09T15:44:29.000Z","size":35,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-13T18:34:01.854Z","etag":null,"topics":["go","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abusomani.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":"2023-03-06T13:13:02.000Z","updated_at":"2023-09-26T23:00:40.000Z","dependencies_parsed_at":"2024-01-07T21:54:03.142Z","dependency_job_id":"860fdd92-8a23-4da8-9421-0308e9c2278d","html_url":"https://github.com/abusomani/jsonhandlers","commit_stats":null,"previous_names":["abusomani/easyjson"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/abusomani/jsonhandlers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abusomani%2Fjsonhandlers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abusomani%2Fjsonhandlers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abusomani%2Fjsonhandlers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abusomani%2Fjsonhandlers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abusomani","download_url":"https://codeload.github.com/abusomani/jsonhandlers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abusomani%2Fjsonhandlers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30310782,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T20:05:46.299Z","status":"ssl_error","status_checked_at":"2026-03-09T19:57:04.425Z","response_time":61,"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","golang","json"],"created_at":"2024-07-30T20:01:36.549Z","updated_at":"2026-03-09T20:32:44.176Z","avatar_url":"https://github.com/abusomani.png","language":"Go","funding_links":[],"categories":["JSON"],"sub_categories":["Search and Analytic Databases","检索及分析资料库"],"readme":"\u003ch1 align=\"center\"\u003eJsonHandlers\u003c/h1\u003e\n\n\u003cdiv align=\"center\" id=\"top\"\u003e \n  \u003cimg src=\"https://res.cloudinary.com/dahkenlmo/image/upload/v1678346700/jsonhandlers_hjca2i.png\" alt=\"Json Handlers\" /\u003e\n  \u0026#xa0;\n\u003c/div\u003e\n\n\n\u003cp align=\"center\"\u003eJSON library to expose simple handlers that lets you easily read and write json from various sources.\u003c/p\u003e\n\n\n[![Build Status](https://github.com/abusomani/jsonhandlers/workflows/build/badge.svg)](https://github.com/abusomani/jsonhandlers/actions)\n[![Github top language](https://img.shields.io/github/languages/top/abusomani/jsonhandlers)](https://img.shields.io/github/languages/top/abusomani/jsonhandlers)\n[![Github language count](https://img.shields.io/github/languages/count/abusomani/jsonhandlers)](https://img.shields.io/github/languages/count/abusomani/jsonhandlers)\n[![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/abusomani/jsonhandlers/blob/main/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/abusomani/jsonhandlers)](https://goreportcard.com/report/github.com/abusomani/jsonhandlers)\n[![Go Reference](https://pkg.go.dev/badge/github.com/abusomani/jsonhandlers.svg)](https://pkg.go.dev/github.com/abusomani/jsonhandlers)\n[![Repo size](https://img.shields.io/github/repo-size/abusomani/jsonhandlers)](https://shields.io/github/repo-size/abusomani/jsonhandlers)\n[![Coverage Status](https://coveralls.io/repos/github/abusomani/jsonhandlers/badge.svg?branch=main)](https://coveralls.io/github/abusomani/jsonhandlers?branch=main)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go#json)\n\n\n## Prerequisites\n\nA go module where you want to integrate jsonhandlers. To create one, follow this [guide](https://go.dev/doc/tutorial/create-module).\n\n## Installation\n\n```\ngo get github.com/abusomani/jsonhandlers\n```\n\n\n## Usage\n\nA very useful feature of Go’s import statement are aliases. A common use case for import aliases is to provide a shorter alternative to a library’s package name.\n\nIn this example, we save ourselves having to type `jsonhandlers` everytime we want to call one of the library’s functions, we just use `jh` instead.\n\n```\nimport (\n    jh \"github.com/abusomani/jsonhandlers\"\n)\n```\n\n## Options\n\nJsonhandlers package exposes multiple options while creating a new `jsonhandler` to be able to read/write json from sources like Files, Http Requests or Http responses. \n\n\n### WithFileHandler\n\nYou can use the `WithFileHandler` option to read/write Json from/to a file. For this, you need to create a new jsonhandler with the file handler option.\n\n[Example](./example/operations/file_handling.go) to understand `WithFileHandler` in more detail.\n\n**Sample Code**\n```go\npackage operations\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/abusomani/jsonhandlers\"\n)\n\n\nfunc handleFile() {\n\tjh := jsonhandlers.New(jsonhandlers.WithFileHandler(testFilePath))\n\n\tvar sch school\n\terr := jh.Unmarshal(\u0026sch)\n}\n\n```\n\n### WithHTTPRequestHandler\n\nYou can use the `WithHTTPRequestHandler` option to read Json from a Http Request and to write Json to a Http ResponseWriter. For this, you need to create a new jsonhandler with the Http request handler option.\n\n[Example](./example/operations/http_request_handling.go) to understand `WithHTTPRequestHandler` in more detail.\n\n**Sample Code**\n```go\npackage operations\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/abusomani/jsonhandlers\"\n)\n\ntype studentSearchRequest struct {\n\tName string\n}\n\ntype studentSearchResponse struct {\n\tInfo student\n}\n\nfunc HandleHTTPRequest(students []student) http.Handler {\n\treturn http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\t\n    \tjh := jsonhandlers.New(jsonhandlers.WithHTTPRequestHandler(w, r))\n\n\t\tvar reqBody studentSearchRequest\n\t\t_ := jh.Unmarshal(\u0026reqBody)\n\t\t\n\n\t\tfor _, student := range students {\n\t\t\t// student found\n\t\t\tif student.Name == reqBody.Name {\n\t\t\t\t\n\t\t\t\t// write the response using jh.Marshal\n\t\t\t\tjh.Marshal(studentSearchResponse{\n\t\t\t\t\tInfo: student,\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t})\n}\n\n/*\n  Sample request to be hit on the localhost server to test WithHTTPRequestHandler functionality.\n  curl http://localhost:8080/search -d '{\"Name\": \"Abhishek Somani\"}'\n*/\n```\n\n### WithHTTPResponseHandler\n\nYou can use the `WithHTTPResponseHandler` option to read/write Json from/to a Http Response. For this, you need to create a new jsonhandler with the Http response handler option.\n\n[Example](./example/operations/http_response_handling.go) to understand `WithHTTPResponseHandler` in more detail.\n\n**Sample Code**\n\n```go\npackage operations\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/abusomani/jsonhandlers\"\n)\n\ntype user struct {\n\tId        int\n\tFirstName string\n\tLastName  string\n}\n\ntype getUsersResponse struct {\n\tUsers []user\n}\n\nfunc HandleHTTPResponse() {\n\tresp, _ := http.Get(\"https://dummyjson.com/users\")\n\tjh := jsonhandlers.New(jsonhandlers.WithHTTPResponseHandler(resp))\n\n\tvar userResp getUsersResponse\n\tjh.Unmarshal(\u0026userResp)\n}\n\n```\n\n## Run examples\nTo run the examples present in the [example](./example/) folder you need to first checkout this package by doing a `git clone`. Once you have checked out this package, then you can run the [main.go](./example/main.go) using the following command to see all the examples in action:\n\n```\ngo run example/main.go\n```\n\n\n## License\nLicensed under [MIT](./LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabusomani%2Fjsonhandlers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabusomani%2Fjsonhandlers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabusomani%2Fjsonhandlers/lists"}