mholt/json-to-go

Translates JSON into a Go type in your browser instantly (original)

JavaScript

4,622

78 commits

updated Jul 31, 2024

See the code

README

JSON-to-Go converts JSON to a Go struct

Translates JSON into a Go type definition. Check it out!

This is a sister tool to curl-to-Go, which converts curl commands to Go code.

Things to note:

  • The script sometimes has to make some assumptions, so give the output a once-over.
  • In an array of objects, it is assumed that the first object is representative of the rest of them.
  • The output is indented, but not formatted. Use go fmt!

Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.

Usage

  • Read JSON file:

    node json-to-go.js sample.json
    
  • Read JSON file from stdin:

    node json-to-go.js < sample.json
    cat sample.json | node json-to-go.js
    

Credits

JSON-to-Go is brought to you by Matt Holt (mholt6).

The Go Gopher is originally by Renee French. This artwork is an adaptation.

go
golang
json
translates-json

mholt/json-to-go

Translates JSON into a Go type in your browser instantly (original)

JavaScript

4,622

78 commits

updated Jul 31, 2024

See the code

README

JSON-to-Go converts JSON to a Go struct

Translates JSON into a Go type definition. Check it out!

This is a sister tool to curl-to-Go, which converts curl commands to Go code.

Things to note:

  • The script sometimes has to make some assumptions, so give the output a once-over.
  • In an array of objects, it is assumed that the first object is representative of the rest of them.
  • The output is indented, but not formatted. Use go fmt!

Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.

Usage

  • Read JSON file:

    node json-to-go.js sample.json
    
  • Read JSON file from stdin:

    node json-to-go.js < sample.json
    cat sample.json | node json-to-go.js
    

Credits

JSON-to-Go is brought to you by Matt Holt (mholt6).

The Go Gopher is originally by Renee French. This artwork is an adaptation.

go
golang
json
translates-json

Project health

Overall

3.3/10

Maintained

0/10

Code review

5/10
OpenSSF Scorecard

Significant stargazers

(top 24 of 45)

Sebastiaan van Stijn

1,978 followers · starred Mar 2017

Simon Ser

2,179 followers · starred Jul 2017

Chris Penner

492 followers · starred Nov 2020

Su Yang

2,490 followers · starred Nov 2021