{"id":20950795,"url":"https://github.com/cneill/jsonstruct","last_synced_at":"2026-05-18T03:36:27.815Z","repository":{"id":57619223,"uuid":"382966516","full_name":"cneill/jsonstruct","owner":"cneill","description":"Create Go structs from JSON examples","archived":false,"fork":false,"pushed_at":"2023-09-19T04:14:38.000Z","size":481,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-07T21:25:48.440Z","etag":null,"topics":["golang","json","tools"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cneill.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-04T23:21:20.000Z","updated_at":"2024-07-04T16:53:03.000Z","dependencies_parsed_at":"2024-06-20T04:41:34.450Z","dependency_job_id":null,"html_url":"https://github.com/cneill/jsonstruct","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/cneill/jsonstruct","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cneill%2Fjsonstruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cneill%2Fjsonstruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cneill%2Fjsonstruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cneill%2Fjsonstruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cneill","download_url":"https://codeload.github.com/cneill/jsonstruct/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cneill%2Fjsonstruct/sbom","scorecard":{"id":294614,"data":{"date":"2025-08-11","repo":{"name":"github.com/cneill/jsonstruct","commit":"9801995e5d057a74280faf89bbcc828fa3f9664d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.7,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/7 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: topLevel 'contents' permission set to 'write': .github/workflows/release.yaml:8","Warn: no topLevel permission defined: .github/workflows/test-and-lint.yaml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yaml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/cneill/jsonstruct/release.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yaml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/cneill/jsonstruct/release.yaml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yaml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/cneill/jsonstruct/release.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-and-lint.yaml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/cneill/jsonstruct/test-and-lint.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-and-lint.yaml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/cneill/jsonstruct/test-and-lint.yaml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test-and-lint.yaml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/cneill/jsonstruct/test-and-lint.yaml/master?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":10,"reason":"project is fuzzed","details":["Info: GoBuiltInFuzzer integration found: parser_test.go:110","Info: GoBuiltInFuzzer integration found: utils_test.go:44"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD 3-Clause \"New\" or \"Revised\" License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v1.1.0 not signed: https://api.github.com/repos/cneill/jsonstruct/releases/121559934","Warn: release artifact v1.0.0 not signed: https://api.github.com/repos/cneill/jsonstruct/releases/120919335","Warn: release artifact v1.1.0 does not have provenance: https://api.github.com/repos/cneill/jsonstruct/releases/121559934","Warn: release artifact v1.0.0 does not have provenance: https://api.github.com/repos/cneill/jsonstruct/releases/120919335"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 25 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T19:09:33.089Z","repository_id":57619223,"created_at":"2025-08-17T19:09:33.089Z","updated_at":"2025-08-17T19:09:33.089Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33163801,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"online","status_checked_at":"2026-05-18T02:00:06.436Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["golang","json","tools"],"created_at":"2024-11-19T00:52:38.649Z","updated_at":"2026-05-18T03:36:27.797Z","avatar_url":"https://github.com/cneill.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonstruct\n\n[![Test and lint](https://github.com/cneill/jsonstruct/actions/workflows/test-and-lint.yaml/badge.svg)](https://github.com/cneill/jsonstruct/actions/workflows/test-and-lint.yaml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/cneill/jsonstruct.svg)](https://pkg.go.dev/github.com/cneill/jsonstruct)\n[![Go Report Card](https://goreportcard.com/badge/github.com/cneill/jsonstruct)](https://goreportcard.com/report/github.com/cneill/jsonstruct)\n\n`jsonstruct` is both a library and a command line tool to produce Go structs based on example JSON text. I just\nrefactored this pretty heavily, so there may still be bugs. It uses [`gofumpt`](https://github.com/mvdan/gofumpt) to\nformat its output.\n\n## Installation\n\n```bash\ngo install github.com/cneill/jsonstruct/cmd/jsonstruct@latest\n```\n\n## Usage\n\n```\nNAME:\n   jsonstruct - generate Go structs for JSON values\n\nUSAGE:\n   jsonstruct [global options] command [command options] [FILE]...\n\nDESCRIPTION:\n   You can either pass in files as args or JSON in STDIN. Results are printed to STDOUT.\n\nCOMMANDS:\n   http     run a web app to generate structs in the browser\n   help, h  Shows a list of commands or help for one command\n\nGLOBAL OPTIONS:\n   --name value, -n value    override the default name derived from filename\n   --value-comments, -c      add a comment to struct fields with the example value(s) (default: false)\n   --sort-fields, -s         sort the fields in alphabetical order; default behavior is to mirror input (default: false)\n   --inline-structs, -i      use inline structs instead of creating different types for each object (default: false)\n   --print-filenames, -f     print the filename above the structs defined within (default: false)\n   --out-file FILE, -o FILE  write the results to FILE\n   --debug, -d               enable debug logs (default: false)\n   --help, -h                show help\n```\n\n## Examples\n\n### Webapp\n\n![http-screenshot](./img/http-screenshot.png)\n\nThe `http` command allows you to run a webapp to generate these structs in the browser.\n\n### JSON object\n\n**Input:**\n\n```json\n{\n    \"currency\": \"value\",\n    \"amount\": 4.267,\n    \"map\": {\n        \"something\": \"nothing\",\n        \"this\": true\n    },\n    \"array\": [\n        1,\n        2,\n        3,\n        4\n    ],\n    \"string_array\": [\n        \"string\",\n        \"string2\",\n        \"string3\"\n    ],\n    \"CamelKey\": \"blah\",\n    \"blahBlahBlah\": \"blah\",\n    \"structs\": [\n        {\n            \"stuff\": \"stuff\"\n        },\n        {\n            \"stuff\": \"stuff2\"\n        },\n        {\n            \"stuff\": \"stuff3\",\n            \"differentStuff\": \"differentStuff\"\n        }\n    ],\n    \"nested_numbers\": [\n        [1, 2, 3],\n        [2, 3, 4],\n        [3, 4, 5]\n    ],\n    \"nothing\": null\n}\n```\n\n**Output:**\n\n```golang\ntype Stdin1 struct {\n        Currency      string   `json:\"currency\"`\n        Amount        float64  `json:\"amount\"`\n        Map           *Map     `json:\"map\"`\n        Array         []int64  `json:\"array\"`\n        StringArray   []string `json:\"string_array\"`\n        CamelKey      string\n        BlahBlahBlah  string           `json:\"blahBlahBlah\"`\n        Structs       []*Structs       `json:\"structs\"`\n        NestedNumbers [][]int64        `json:\"nested_numbers\"`\n        Nothing       *json.RawMessage `json:\"nothing\"`\n}\n\ntype Map struct {\n        Something string `json:\"something\"`\n        This      bool   `json:\"this\"`\n}\n\ntype Structs struct {\n        Stuff          string `json:\"stuff\"`\n        DifferentStuff string `json:\"differentStuff,omitempty\"`\n}\n```\n\n### JSON array of objects\n\n**Input:**\n\n```json\n[\n    {\n        \"stuff\": \"stuff\"\n    },\n    {\n        \"stuff\": \"stuff2\"\n    },\n    {\n        \"stuff\": \"stuff3\",\n        \"differentStuff\": \"differentStuff\"\n    },\n    {\n        \"stuff\": 1,\n        \"differentStuff\": \"blah\"\n    }\n]\n```\n\n**Output:**\n\n```golang\ntype Stdin1 struct {\n        Stuff          *json.RawMessage `json:\"stuff\"`\n        DifferentStuff string           `json:\"differentStuff,omitempty\"`\n}\n```\n\n### Value comments (`-c`)\n\n**Input:**\n\n```json\n{\n  \"test_bool\": true,\n  \"test_int64\": 1234,\n  \"test_float64\": 1234.0,\n  \"test_string\": \"test\",\n  \"test_array_of_bool\": [true, false, true],\n  \"test_array_of_int64\": [1, 2, 3, 4],\n  \"test_array_of_float64\": [1.0, 2.0, 3.0, 4.0],\n  \"test_array_of_string\": [\"test1\", \"test2\", \"test3\"],\n  \"test_struct\": {\n    \"test_string\": \"test\",\n    \"test_array_of_string\": [\"test1\", \"test2\", \"test3\"]\n  },\n  \"test_array_of_struct\": [\n    {\n      \"test_string\": \"test1\",\n      \"test_optional_string\": \"test1\"\n    },\n    {\n      \"test_string\": \"test2\",\n      \"test_optional_string\": \"test2\"\n    },\n    {\n      \"test_string\": \"test3\"\n    },\n    {\n      \"test_string\": \"test4\"\n    }\n  ],\n  \"test_garbage_array\": [1, \"1\", 1.0],\n  \"terrible-name.for_a.key\": \"test\"\n}\n```\n\n**Output:**\n\n```golang\ntype Stdin1 struct {\n        TestBool            bool                 `json:\"test_bool\"`             // Example: true\n        TestInt64           int64                `json:\"test_int64\"`            // Example: 1234\n        TestFloat64         float64              `json:\"test_float64\"`          // Example: 1234.000\n        TestString          string               `json:\"test_string\"`           // Example: \"test\"\n        TestArrayOfBool     []bool               `json:\"test_array_of_bool\"`    // Example: [true, false, true]\n        TestArrayOfInt64    []int64              `json:\"test_array_of_int64\"`   // Example: [1, 2, 3, 4]\n        TestArrayOfFloat64  []float64            `json:\"test_array_of_float64\"` // Example: [1.000, 2.000, 3.000, 4.000]\n        TestArrayOfString   []string             `json:\"test_array_of_string\"`  // Example: [\"test1\", \"test2\", \"test3\"]\n        TestStruct          *TestStruct          `json:\"test_struct\"`\n        TestArrayOfStruct   []*TestArrayOfStruct `json:\"test_array_of_struct\"`\n        TestGarbageArray    []*json.RawMessage   `json:\"test_garbage_array\"`\n        TerribleNameForAKey string               `json:\"terrible-name.for_a.key\"` // Example: \"test\"\n}\n\ntype TestStruct struct {\n        TestString        string   `json:\"test_string\"`          // Example: \"test\"\n        TestArrayOfString []string `json:\"test_array_of_string\"` // Example: [\"test1\", \"test2\", \"test3\"]\n}\n\ntype TestArrayOfStruct struct {\n        TestString         string `json:\"test_string\"`                    // Example: \"test1\"\n        TestOptionalString string `json:\"test_optional_string,omitempty\"` // Example: \"test1\"\n}\n```\n\n### Inline struct definitions (`-i`)\n\n**Input:**\n\n```json\n{\n  \"test_struct\": {\n    \"test_string\": \"test\",\n    \"test_array_of_string\": [\"test1\", \"test2\", \"test3\"]\n  },\n  \"test_array_of_struct\": [\n    {\n      \"test_string\": \"test1\",\n      \"test_optional_string\": \"test1\"\n    },\n    {\n      \"test_string\": \"test2\",\n      \"test_optional_string\": \"test2\"\n    },\n    {\n      \"test_string\": \"test3\"\n    },\n    {\n      \"test_string\": \"test4\"\n    }\n  ]\n}\n```\n\n**Output:**\n\n```golang\ntype Stdin1 struct {\n        TestStruct struct {\n                TestString        string   `json:\"test_string\"`\n                TestArrayOfString []string `json:\"test_array_of_string\"`\n        } `json:\"test_struct\"`\n        TestArrayOfStruct []struct {\n                TestString         string `json:\"test_string\"`\n                TestOptionalString string `json:\"test_optional_string,omitempty\"`\n        } `json:\"test_array_of_struct\"`\n}\n```\n\n## Notes\n\n* When an array of JSON objects is detected, any keys that are provided in some objects but not others\n  will get the `,omitempty` flag\n* When the same field is detected in multiple objects in a JSON array with different value types, the\n  Go type will be `*json.RawMessage`, which will contain the raw bytes of the field to allow for\n  different types\n* Defaults to a `*json.RawMessage` type when:\n    * JSON `null` is provided\n    * There are multiple types in e.g. an array\n    * There is an empty array\n* Can take input from either files passed in as CLI args or STDIN. Can take a stream of objects / arrays of objects.\n\n## TODO\n\n* De-duplicate structs that are created more than once by multiple instances in the example JSON file\n* Handle plural names for slice types\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcneill%2Fjsonstruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcneill%2Fjsonstruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcneill%2Fjsonstruct/lists"}