Loona Automation logoLoona Developer Tools
Home › Code Generators

JSON to Go Structs

In short: paste JSON and get Go struct definitions with correct json tags — nested objects become named structs, integers type as int64 and decimals as float64.
🔒 Private by design: everything runs in your browser on this device. Your input is never uploaded to a server.

Example

Input:

{"name": "Ali", "age": 30}

Output:

package main

type Root struct {
	Name string `json:"name"`
	Age int64 `json:"age"`
}

About this converter

Go's encoding/json needs struct shapes declared, and writing them by hand from a sample payload is exactly the chore this automates. Field names are PascalCased (with the original key preserved in the json tag, plus ,omitempty for keys missing from some items of an array input). Types follow Go conventions: whole numbers int64, decimals float64, nested objects extracted as separate named structs so they can be reused. Watch two honest limits: a number that happens to be whole in the sample (30) types as int64 even if the API later sends 30.5 — widen it manually; and single-letter or acronym keys (id, url) PascalCase to Id/Url rather than the idiomatic ID/URL — a thirty-second rename in your editor.

Frequently Asked Questions

Why int64 and not int?

JSON numbers have no fixed width; int64 is the safe default that encoding/json unmarshals whole values into without overflow on 64-bit platforms.

Can it handle arrays of mixed objects?

Yes — keys are merged across items and missing keys get ,omitempty, matching how ragged API payloads behave.

Related Developer Tools

Embed this tool on your website — free

Add this tool to your own website or blog — it is completely free, needs no sign-up, and always shows the latest version. Copy the code below and paste it into your page where you want the tool to appear. Keeping the small “Powered by Loona Automation” credit line under the embed helps keep this tool free — but you are free to style or remove it; the tool works either way.