{"id":21054649,"url":"https://github.com/bemasher/jsongen","last_synced_at":"2025-05-15T22:34:18.320Z","repository":{"id":9352087,"uuid":"11203624","full_name":"bemasher/JSONGen","owner":"bemasher","description":"JSONGen is a tool for generating native Golang types from JSON objects.","archived":false,"fork":false,"pushed_at":"2015-01-22T06:07:20.000Z","size":436,"stargazers_count":210,"open_issues_count":0,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-03T16:13:04.467Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bemasher.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":"2013-07-05T16:16:48.000Z","updated_at":"2025-03-30T19:49:01.000Z","dependencies_parsed_at":"2022-09-06T00:21:30.650Z","dependency_job_id":null,"html_url":"https://github.com/bemasher/JSONGen","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/bemasher%2FJSONGen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bemasher%2FJSONGen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bemasher%2FJSONGen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bemasher%2FJSONGen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bemasher","download_url":"https://codeload.github.com/bemasher/JSONGen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254433552,"owners_count":22070492,"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-11-19T16:15:53.563Z","updated_at":"2025-05-15T22:34:15.139Z","avatar_url":"https://github.com/bemasher.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Purpose\nJSONGen is a tool for generating native Golang types from JSON objects. This automates what is otherwise a very tedious and error prone task when working with JSON.\n\n[![Build Status](http://img.shields.io/travis/bemasher/JSONGen.svg?style=flat)](https://travis-ci.org/bemasher/JSONGen)\n[![GPLv3 License](http://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](http://choosealicense.com/licenses/gpl-3.0/)\n\n## Usage\n\n```\n$ jsongen -h\nUsage of jsongen:\n  -dump=\"NUL\": Dump tree structure to file.\n  -normalize=true: Squash arrays of struct and determine primitive array type.\n  -title=true: Convert identifiers to title case, treating '_' and '-' as word boundaries.\n```\n\nReading from stdin can be done as follows:\n```\n$ cat test.json | jsongen\n```\n\nOr a filename can be passed:\n```\n$ jsongen test.json\n```\n\nUsing [test.json](test.json) as input the example will produce:\n```go\ntype _ struct {\n\tBool              bool          `json:\"bool\"`\n\tBoollist          []bool        `json:\"boollist\"`\n\tFloat             float64       `json:\"float\"`\n\tFloatlist         []float64     `json:\"floatlist\"`\n\tHeterogeneouslist []interface{} `json:\"heterogeneouslist\"`\n\tInt               int64         `json:\"int\"`\n\tIntlist           []int64       `json:\"intlist\"`\n\tNil               interface{}   `json:\"nil\"`\n\tNillist           []interface{} `json:\"nillist\"`\n\tSanitary          string        `json:\"_Sanitary\"`\n\tSanitary          string\n\tSanitary0         string\n\tString            string   `json:\"string\"`\n\tStringlist        []string `json:\"stringlist\"`\n\tStruct            struct {\n\t\tBool   bool        `json:\"bool\"`\n\t\tFloat  float64     `json:\"float\"`\n\t\tInt    int64       `json:\"int\"`\n\t\tNil    interface{} `json:\"nil\"`\n\t\tString string      `json:\"string\"`\n\t} `json:\"struct\"`\n\tStructlist []struct {\n\t\tBool   bool    `json:\"bool\"`\n\t\tFloat  float64 `json:\"float\"`\n\t\tInt    int64   `json:\"int\"`\n\t\tString string  `json:\"string\"`\n\t} `json:\"structlist\"`\n\tStructlistsquash []struct {\n\t\tBool   bool    `json:\"bool\"`\n\t\tFloat  float64 `json:\"float\"`\n\t\tInt    int64   `json:\"int\"`\n\t\tString string  `json:\"string\"`\n\t} `json:\"structlistsquash\"`\n\tStructlistsquashconflict []struct {\n\t\tBool     bool        `json:\"bool\"`\n\t\tConflict interface{} `json:\"conflict\"`\n\t\tFloat    float64     `json:\"float\"`\n\t\tInt      int64       `json:\"int\"`\n\t\tString   string      `json:\"string\"`\n\t} `json:\"structlistsquashconflict\"`\n\tTitleCase  string `json:\"title case\"`\n\tTitleCase  string `json:\"title_case\"`\n\tTitleCase  string `json:\"title-case\"`\n\tTitlecase  string `json:\"titlecase\"`\n\tUnsanitary string `json:\"0Unsanitary\"`\n\t_          string `json:\"123\"`\n}\n```\n\n## Parsing\n### Field Names\n  * Field names are sanitized and written as exported fields of the generated type.\n  * If sanitizing produces an empty string the identifier is changed to `_`, this will need to be set by hand in order to properly decode the type.\n  * If sanitizing produces a field name different from the original value a JSON tag is added to the field.\n  * Spaces and `-` are converted to `_`.\n  * Field names are converted to title case treating `_` and `-` as word boundaries along with spaces. This can be disabled using `-title=false`.\n\n## Types\n### Primitive\n  * Primitive types are parsed and stored as-is.\n  * Valid types are bool, int64, float64 and string.\n  * The JSON value `null` is translated to the empty interface.\n\n### Object\n  * Object types are treated as structs.\n  * Fields of structures are sorted lexicographically by sanitized field name.\n  * If a structure contains duplicate fields of different types, the type will be chosen at random since Golang's map iteration order is undefined. This shouldn't be a problem since this is not permitted in JSON specification, but this is the expected behavior should it happen.\n\n### Lists\n  * A homogeneous list of primitive values are treated as a list of the primitive type e.g.: `[]float64`\n  * Lists of heterogeneous types are treated as a list of the empty interface: `[]interface{}`\n  * Lists containing both integers and floating point values are interpreted as `[]float64`.\n  * Lists with object elements are treated as a list of structs.\n    * Fields of each element are \"squashed\" into a single struct. The result is an array of a struct containing all encountered fields.   \n    * If a field in one element has a different type in another of the same list, the offending field is treated as an empty interface.\n\nExamples of all of the above can be found in [test.json](test.json).\n\n## Caveats\n  * Currently sibling field names are not guaranteed to be unique.\n\n## License\nThe source of this project is licensed under GNU GPL v3.0, according to [http://choosealicense.com/licenses/gpl-3.0/](http://choosealicense.com/licenses/gpl-3.0/):\n\n#### Required:\n\n * **Disclose Source:** Source code must be made available when distributing the software. In the case of LGPL, the source for the library (and not the entire program) must be made available.\n * **License and copyright notice:** Include a copy of the license and copyright notice with the code.\n * **State Changes:** Indicate significant changes made to the code.\n\n#### Permitted:\n\n * **Commercial Use:** This software and derivatives may be used for commercial purposes.\n * **Distribution:** You may distribute this software.\n * **Modification:** This software may be modified.\n * **Patent Grant:** This license provides an express grant of patent rights from the contributor to the recipient.\n * **Private Use:** You may use and modify the software without distributing it.\n\n#### Forbidden:\n\n * **Hold Liable:** Software is provided without warranty and the software author/license owner cannot be held liable for damages.\n * **Sublicensing:** You may not grant a sublicense to modify and distribute this software to third parties not included in the license.\n\n## Feedback\nIf you find a case that produces incorrect results or you have a feature suggestion, let me know: submit an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbemasher%2Fjsongen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbemasher%2Fjsongen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbemasher%2Fjsongen/lists"}