{"id":13831992,"url":"https://github.com/marhaupe/json2struct","last_synced_at":"2025-07-09T15:34:14.140Z","repository":{"id":57554827,"uuid":"158816678","full_name":"marhaupe/json2struct","owner":"marhaupe","description":"CLI tool to convert JSON to struct type definitions","archived":false,"fork":false,"pushed_at":"2024-08-04T23:33:24.000Z","size":1420,"stargazers_count":92,"open_issues_count":3,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-05T10:19:45.252Z","etag":null,"topics":["cli","generator","go","golang","json","json-parser","json2struct","struct"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marhaupe.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":"2018-11-23T10:22:28.000Z","updated_at":"2024-08-04T23:33:27.000Z","dependencies_parsed_at":"2024-01-15T15:46:05.799Z","dependency_job_id":"6d476d6a-fd0e-4752-ab43-46d7b93c0ee2","html_url":"https://github.com/marhaupe/json2struct","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marhaupe%2Fjson2struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marhaupe%2Fjson2struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marhaupe%2Fjson2struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marhaupe%2Fjson2struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marhaupe","download_url":"https://codeload.github.com/marhaupe/json2struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225565961,"owners_count":17489290,"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":["cli","generator","go","golang","json","json-parser","json2struct","struct"],"created_at":"2024-08-04T10:01:46.892Z","updated_at":"2025-07-09T15:34:14.097Z","avatar_url":"https://github.com/marhaupe.png","language":"Go","readme":"# json2struct\n\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\n\u003c!-- [![GoDoc](https://godoc.org/github.com/marhaupe/json2struct?status.svg)](https://godoc.org/github.com/marhaupe/json2struct) --\u003e\n\n\u003e CLI tool to convert JSON to struct type definitions\n\nAt some point when dealing with JSONs in Go, you will have to write struct types to `json.Unmarshal` your JSONs into. Doing this by hand is not only repetitive and time consuming, but also error prone. `json2struct` saves you this work by automatically parsing the JSON and generating you the matching struct type definitions ready to be used.\n\nUnlike other tools, `json2struct` tries to avoid generating `interface{}` and `map[string]interface{}` as much as possible. Nonetheless it's very [fast](#benchmarks) 🚀.\n\n## Installation\n\n### Homebrew\n\n```bash\nbrew tap marhaupe/json2struct https://github.com/marhaupe/json2struct\n\nbrew install marhaupe/json2struct/json2struct\n```\n\n### Manually\n\nGrab the latest release [binaries](https://github.com/marhaupe/json2struct/releases).\n\n## Usage\n\n\u003e json2struct [options]\n\nCalling `json2struct` without flags opens a text editor. Simply input your JSON and save and exit.\n\n![Example](.github/demo.gif)\n\n### Options\n\nYou probably don't want to manually write that 1MB JSON you have to generate a struct for by hand. I mean, if you really want to, I'm not here to judge, but that's not the point. These options will make your life easier. If you miss some, feel free to open an issue.\n\n#### Generating a struct from a string\n\n\u003e -s, --string string: JSON string\n\nThis is basically your bread and butter thanks to pipes. Usage:\n\n```bash\n json2struct -s \"$(curl \"https://reqres.in/api/users?page=2\")\"\n```\n\n#### Generating a struct from an existing file\n\n\u003e -f, --file string: path to JSON file\n\nThis is useful if you have a JSON file stored in your filesystem and are too lazy to use pipes. Usage:\n\n```bash\njson2struct -f input.json\n```\n\n#### Generating a struct from the clipboard to the clipboard\n\n\u003e -c, --clipboard: read from and write types to clipboard\n\nReads JSON from clipboard, generates types and writes those types to the clipboard.\n\n```bash\njson2struct -c\n```\n\n#### Other options\n\n\u003e -b, --benchmark: measure execution time\n\n\u003e -h, --help: help for json2struct\n\n\u003e --version: version for json2struct\n\n\n\n## Benchmarks\n\n| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |\n|:---|---:|---:|---:|---:|\n| `json2struct -f big_reddit_response` | 8.1 ± 0.6 | 7.3 | 11.3 | 1.00 |\n| `gojson -input big_reddit_response` | 9.0 ± 0.5 | 8.1 | 10.8 | 1.12 ± 0.10 |\n| `cat big_reddit_response \\| gojsonstruct` | 71.7 ± 1.3 | 69.9 | 76.9 | 8.87 ± 0.64 |\n| `quicktype -l go -o output.go big_reddit_response` | 329.5 ± 2.2 | 326.7 | 333.5 | 40.75 ± 2.86 |\n\n## Specifics\n\nA lot of the lexing/parsing in this project is inspired by the [`text/template`](https://go.dev/src/text/template/) package. Rob Pike also gave a talk about how and why they wrote the package. The link can be found [here](https://www.youtube.com/watch?v=HxaD_trXwRE), and the slides to it [here](https://go.dev/talks/2011/lex.slide#1)\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarhaupe%2Fjson2struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarhaupe%2Fjson2struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarhaupe%2Fjson2struct/lists"}