Golang: Struct Tagging for playing nice with data marshalling

{suffix: "day", toRemove: true}
package hour20import (
"encoding/json"
"fmt"
"testing"
)
type suffixStruct struct {
Suffix string
ToRemove bool
}
func TestJsonToStruct(t *testing.T) {
jsonString := `{
suffix: "day",
toRemove: true,
}` //multiline string
aSuffix := suffixStruct{}err := json.Unmarshal([]byte(jsonString), &aSuffix)
if err != nil {
t.Fatal(err)
}
fmt.Printf("%+v\n", aSuffix)}
type suffixStruct struct {
Suffix string
IsRemove bool
}
type suffixStruct struct {
Suffix string
IsRemove bool `json:"toRemove"`
}

--

--

--

Writing to soothe the soul, programming to achieve flow

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

80 to 800+: The story of my four years on the Elastic rocket ship, Part 1

Collecting logs for Docker Rails application with Datadog

How I applied to for a job and why I’m so excited about it

The CMSC 21 Experience for Me (Module 3)

Restrictions for declaring a class in java

New in Basecamp 3: To-do Groups

Deploying a Django Application to Heroku

The Wicked Android Crashes and How to Disarm them

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mipsmonsta

Mipsmonsta

Writing to soothe the soul, programming to achieve flow

More from Medium

Dealing with multiple workers - A Go layman approach

Golang in sixty seconds — converting to JSON

Photo of JSON business card, showing logo and text “JSON Data Interchange Format”

Delve With VSCode To Debug Go App

Functions in GO