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
+6.7k Golang : Experimental emojis or emoticons icons programming language
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+15k Golang : package is not in GOROOT during compilation
+6.9k Golang : Pat multiplexer routing example
+11.6k Android Studio : Create custom icons for your application example
+34k Golang : Proper way to set function argument default value
+28.5k Golang : Change a file last modified date and time
+12.1k Golang : Perform sanity checks on filename example
+5.6k PHP : Convert CSV to JSON with YQL example
+6.6k Golang : How to determine if request or crawl is from Google robots
+7.5k Golang : How to handle file size larger than available memory panic issue
+27.9k Golang : Decode/unmarshal unknown JSON data type with map[string]interface