I have the following examples.
1
package main
import (
"encoding/json"
"fmt"
)
type JSType struct {
Value string `json:value`
Empty string `json:empty`
}
func main() {
str := `{"value": "base64", "empty": "", "params": {}}`
var decoded JSType
metaBin := []byte(str)
json.Unmarshal(metaBin, &decoded)
fmt.Println(decoded.Empty)
}
It returns an empty string which is expected.
2
package main
import (
"encoding/json"
"fmt"
)
type JSType struct {
Value string `json:value`
Empty string `json:empty`
}
func main() {
str := `{"value": "base64", "params": {}}`
var decoded JSType
metaBin := []byte(str)
json.Unmarshal(metaBin, &decoded)
fmt.Println(decoded.Empty)
}
in the 2nd example I removed the 'empty' key from the json and it still returns an empty string. So my question is how can I determine if the valie is "" or not defined (key is missing).