Golang encoding/json.Indent() function example
package encoding/json
Indent appends to dst (1st parameter) an indented form of the JSON-encoded src (2nd parameter). Each element in a JSON object or array begins on a new, indented line beginning with prefix(3rd parameter) followed by one or more copies of indent(4th parameter) according to the indentation nesting. The data appended to dst does not begin with the prefix nor any indentation, and has no trailing newline, to make it easier to embed inside other formatted JSON data.
Golang encoding/json.Indent() 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"
}`)
json.Indent(dst, src, "**", "%%")
fmt.Println(dst)
}
Output :
{
**%%"Name": "Adam Ng",
**%%"Age": 36,
**%%"Job": "CEO"
**}
Reference :
Advertisement
Something interesting
Tutorials
+5k Google : Block or disable caching of your website content
+11.7k Golang : Calculations using complex numbers example
+51.1k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+14.7k Golang : Reset buffer example
+14.9k Golang : How to check for empty array string or string?
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+6.6k Golang : Totalize or add-up an array or slice example
+22.4k Golang : Read directory content with filepath.Walk()
+35.3k Golang : Strip slashes from string example
+16.5k Golang : Get IP addresses of a domain name
+6.4k CodeIgniter : form input set_value cause " to become & quot
+15.8k Golang : How to login and logout with JWT example