Skip to content

Commit

Permalink
Example of struct encoding with an ommitted field
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Feb 9, 2019
1 parent 80a4d71 commit 241666b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 2019/gojsoncookbook/struct-omit-field.go
@@ -0,0 +1,22 @@
// Ommitting a struct field when encoding it.
//
// Eli Bendersky [https://eli.thegreenplace.net]
// This code is in the public domain.
package main

import (
"encoding/json"
"fmt"
)

type Account struct {
Name string
Password string `json:"-"`
Balance float64
}

func main() {
joe := Account{Name: "Joe", Password: "123456", Balance: 102.4}
s, _ := json.Marshal(joe)
fmt.Println(string(s))
}

0 comments on commit 241666b

Please sign in to comment.