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
+4.1k Javascript : Empty an array example
+9.4k Facebook : Getting the friends list with PHP return JSON format
+6.1k Golang : Missing Subversion command
+5.8k Cash Flow : 50 days to pay your credit card debt
+21.8k Golang : Convert string slice to struct and access with reflect example
+11.9k Golang : How to parse plain email text and process email header?
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+6.2k PHP : Get client IP address
+4.9k Nginx and PageSpeed build from source CentOS example
+6.3k Golang : Test input string for unicode example
+5.1k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date