JSON / Go Converter


            

JSON / Golang Struct Converter is a free online developer tool to convert between JSON and Golang Struct format.

This tool is split into two modes: JSON to Golang Struct Converter and Golang Struct to JSON Converter.

JSON to Golang Struct Converter - Converts from JSON to Golang Struct. The output Golang Struct.

Golang Struct to JSON Converter - Converts from Golang Struct to JSON.

Once done, you can copy the result to your clipboard using the copy button.

 


Golang Struct Introduction

A struct (short for "structure") is a collection of data fields with declared data types. Golang has the ability to declare and create own data types by combining one or more types, including both built-in and user-defined types. Each data field in a struct is declared with a known type, which could be a built-in type or another user-defined type.

Structs are the only way to create concrete user-defined types in Golang. Struct types are declared by composing a fixed set of unique fields. Structs can improve modularity and allow to create and pass complex data structures around the system. You can also consider Structs as a template for creating a data record, like an employee record or an e-commerce product.

The declaration starts with the keyword type, then a name for the new struct, and finally the keyword struct. Within the curly brackets, a series of data fields are specified with a name and a type.

 

Example

type identifier struct{
  field1 data_type
  field2 data_type
  field3 data_type
}

Declaration of a Struct Type

A struct type rectangle is declared that has three data fields of different data-types. Here, struct used without instantiate a new instance of that type.

Example

package main
 
import "fmt"
 
type rectangle struct {
	length  float64
	breadth float64
	color   string
}
 
func main() {
	fmt.Println(rectangle{10.5, 25.10, "red"})
}

 

The rectangle struct and its fields are not exported to other packages because identifiers are started with an lowercase letter. In Golang, identifiers are exported to other packages if the name starts with an uppercase letter, otherwise the accessibility will be limited within the package only.

More:https://www.golangprograms.com/go-language/struct.html