Menu
PDF Tools
Image Tools
Converters & Utilities
Seller & Print Tools
Accounting & Business
Calculators
Text & Writing Tools
Developer & Web Tools
Creator & Social Tools
Browser Utilities & Games
Document & Design Makers
Text & Developer Tools
Exam & Form Tools

JSON to Go Struct

Paste JSON and get Go struct definitions with json tags. Nested objects become their own named structs, optional fields can use pointers, and date-times can use time.Time.

How to use JSON to Go Struct online

  1. Paste JSON. An object or a list.
  2. Name the top struct and package. Both are editable.
  3. Choose tags and pointers. Omitempty, pointers, int64, time.
  4. Copy the Go code. Paste it into a file.

Why use this free JSON to Go Struct

  • Nested structs
  • Initialisms like ID and URL
  • json tags with omitempty option
  • Pointers for optional fields
  • time.Time for date-times
  • Package line and import

What you get

Go reads JSON through struct fields and tags, and writing them by hand for a big answer is slow and easy to get wrong. This page reads a sample and writes the structs. Each nested object becomes its own struct with a name built from its parent, and lists become slices of the right type.

Field names and tags

Keys are turned into exported Go names. Common short words such as id, url, api and http are written in capitals, so user_id becomes UserID. The original key stays in the tag, so reading and writing JSON keeps working. You can add omitempty to every tag if you want fields left out when they are empty.

Optional and null values

A key that is missing from some objects in a list, or a value that is sometimes null, can be written as a pointer. A pointer tells you the difference between a missing value and a zero value. Keys with only null in the sample become interface{}, because the sample gives no type.

Numbers and dates

Whole numbers become int, or int64 if you ask. A number with a decimal part becomes float64. Because one sample cannot show whether a number may later carry decimals, check the fields that matter. Text that is a date and time in the standard format can become time.Time, and the import line is added for you.

Limits

The structs describe the sample. If an API can send a value in more than one type, the sample may hide that. Read the result, rename fields to suit your code, and try it on real data. Nothing is uploaded.

Using the tool

The result shows under the boxes and refreshes as you edit. Find and replace is built into the editor with Ctrl+F and Ctrl+H.

JSON to Go Struct: frequently asked questions

Can I set the package name?
Yes. Type it in the package field; the default is main.
Why did a field become interface{}?
Its value was null in every sample, or the kinds differed, so no single type was safe.
Does it write methods?
No, only struct types and tags.
What if two nested objects would get the same name?
A number is added to the second name so both compile.
Does it work with a top-level list?
Yes. It writes a slice type and a struct for the items.
Is the text I paste into the JSON to Go Struct uploaded?
It stays in your browser tab; the JSON to Go Struct sends nothing anywhere.
Can I chain the JSON to Go Struct with another tool?
Copy the JSON to Go Struct result, or save it as a text file from the result box.

Related searches for JSON to Go Struct

  • JSON to Go Struct online
  • free JSON to Go Struct
  • JSON to Go Struct online free
  • JSON to Go Struct for mobile
  • JSON to Go Struct without sign up
  • convert json to go struct
  • json to go struct converter
  • JSON to Go Struct – Developer & Web Tools

JSON to Go Struct is a free online tool on MAITBOX, in the Developer & Web Tools group. It runs in your browser, so what you type is not sent to a server. It works on Android and iPhone, and on Windows, Mac and Linux, with no download and no account.

More tools in Developer & Web Tools →

Search tools