A Go package and CLI tool that generates accurate Go struct types from JSON input, ensuring proper marshaling/unmarshaling.
json2go is a Go package and command-line tool that converts JSON data into accurate Go struct type definitions. It solves the problem of manually writing Go types for JSON APIs or documents by automatically generating types that guarantee proper marshaling and unmarshaling, even for complex nested structures with optional fields.
Go developers working with JSON APIs, document-oriented databases, or any system requiring reliable serialization/deserialization between JSON and Go structs.
Developers choose json2go because it produces correct, production-ready type definitions that handle edge cases like null values, optional fields, and mixed document structures—unlike simpler converters that often generate incomplete or incorrect code.
Create go type representation from json
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Extensive test cases ensure generated types accurately marshal and unmarshal input JSON, even with nulls, optional fields, and complex nesting, as validated by the micro acid test example.
Available as a CLI tool, Go package, web interface, and VSCode extension, catering to various development workflows from ad-hoc use to IDE integration.
Correctly processes nested arrays, mixed-type documents, and incremental parsing, allowing feeding multiple JSONs to build unified type definitions for document-oriented databases.
Generates structs with pointers for optional fields, which can make the Go code more cumbersome to work with due to nil checks, compared to simpler tools that might use zero values.
Focuses solely on JSON tags; lacks options for adding XML, database, or other custom struct tags that might be required in projects with multi-format serialization needs.
The emphasis on accuracy and incremental parsing might introduce overhead for very large or simple JSON inputs, though no benchmarks are provided in the README.