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
+14.5k Golang : Find network of an IP address
+6.8k Golang : Find the longest line of text example
+16.5k Golang : Execute terminal command to remote machine example
+4.4k Golang : Valued expressions and functions example
+4.9k Python : Find out the variable type and determine the type with simple test
+6.5k Golang : Map within a map example
+4.9k Nginx and PageSpeed build from source CentOS example
+19.6k Golang : Close channel after ticker stopped example
+33k Golang : How to check if a date is within certain range?
+14k Golang : Compress and decompress file with compress/flate example
+7.3k Golang : How to fix html/template : "somefile" is undefined error?