Golang encoding/json.Compact() function example
package encoding/json
Compact appends to dst(1st parameter) the JSON-encoded src (2nd parameter) with insignificant space characters elided.
Golang encoding/json.Compact() function usage example
package main
import (
"bytes"
"encoding/json"
"fmt"
)
func main() {
dst := new(bytes.Buffer)
src := []byte(`{
"Name":"Adam Ng",
"Age":36,
"Job":"CEO"
}`)
err := json.Compact(dst, src)
if err != nil {
fmt.Println(err)
}
fmt.Println(dst)
}
Output :
{"Name":"Adam Ng","Age":36,"Job":"CEO"}
Reference :
Advertisement
Something interesting
Tutorials
+9.7k PHP : Get coordinates latitude/longitude from string
+9.7k Golang : List available AWS regions
+14.4k Golang : Parsing or breaking down URL
+7.3k Golang : Not able to grep log.Println() output
+4.7k Linux/MacOSX : How to symlink a file?
+11.3k Golang : Characters limiter example
+13.6k Android Studio : Password input and reveal password example
+6.8k Swift : substringWithRange() function example
+5.6k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+5.3k Javascript : Shuffle or randomize array example
+6.5k PHP : Shuffle to display different content or advertisement
+9k Golang : Go as a script or running go with shebang/hashbang style