Golang: Handling Json Post Request Snippet
Create a new Decoder from json package and pass the request body to it! Simple, simple, simple. Try this snippet and enjoy:
Create a new Decoder from json package and pass the request body to it! Simple, simple, simple. Try this snippet and enjoy:
If you want to have a custom key (for example uppercased, lowercased, or even a new name) on the JSON marshal output in golang use… Read More »Golang JSON Marshal With Custom Key (Lowercase, Uppercase …)
Just use this snippet which sends a post request with a JSON body. It saves your time :). I know you are not comfortable with… Read More »Golang HTTP Request With JSON Body
If you want to remove a field from a struct just put `json:”-“` in front of the fields you want to hide: Take a look… Read More »Golang: Removing or Hiding Fields in JSON Marshal
Tags in struct definition are useful when you want to convert structs to other types, especially JSON. Just use the omitempty in front of the… Read More »Golang JSON: How to Make a Field Optional (omitempty)
When debugging a code it is helpful to have a way to simply print the values into the console. If you want the indention and… Read More »Print Struct as String in Golang
You need a simple way to format the output of your marshaled JSON output! Yes, Golang made it easy for us by using MarshalIndent function… Read More »How to Pretty Print JSON in Golang (Marshal Indent)
You have a JSON in string and you want to map its values into a struct, take a look at this simple example:
In Golang convert an object to JSON string (or a slice of bytes) is so simple by using the json package: In this example you… Read More »Golang: Simple Marshal Struct to JSON