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
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+12.8k Golang : Listen and Serve on sub domain example
+6.9k Golang : Fibonacci number generator examples
+17.9k Golang : Simple client server example
+6k Linux/MacOSX : Search for files by filename and extension with find command
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+30.8k Golang : Download file example
+12.2k Golang : Split strings into command line arguments
+5.2k JavaScript/JQuery : Redirect page examples
+21.5k Golang : How to read float value from standard input ?
+6.3k Golang : Detect face in uploaded photo like GPlus
+8.2k Golang : Metaprogramming example of wrapping a function