MCPcopy Index your code
hub / github.com/mholt/json-to-go

github.com/mholt/json-to-go @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
43 symbols 81 edges 6 files 0 documented · 0% updated 1y ago★ 4,62715 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
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:

sh node json-to-go.js sample.json

  • Read JSON file from stdin:

sh 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.

Core symbols most depended-on inside this repo

append
called by 12
json-to-go.js
appender
called by 10
json-to-go.js
format
called by 6
json-to-go.js
goType
called by 5
json-to-go.js
uniqueTypeName
called by 4
json-to-go.js
jsonToGo
called by 3
json-to-go.js
parseScope
called by 3
json-to-go.js
areSameType
called by 3
json-to-go.js

Shape

Function 24
Struct 19

Languages

TypeScript56%
Go44%

Modules by API surface

json-to-go.js21 symbols
tests/duplicate-top-level-structs.go9 symbols
tests/double-nested-objects.go5 symbols
tests/array-with-mixed-float-int.go3 symbols
json-to-go.test.js3 symbols
tests/array-with-nonmatching-types.go2 symbols

For agents

$ claude mcp add json-to-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact