How can I pretty print the object below?
package main
// OBJECT: {
// TABLE: {
// files: [],
// data: {
// CODE: {
// name: "NAME",
// count: 123,
// }
// }
//
// }
import (
"encoding/json"
"fmt"
"log"
)
type Container map[string]*Table
type Table struct {
files []string
data map[string]*Data
}
type Data struct {
name string
count int
}
func main() {
object := Container{
"table1": {
files: []string{"file-1.1"},
data: map[string]*Data{
"XYZ": {
name: "foo",
count: 123,
},
},
},
"table2": {
files: []string{
"file-2.1",
"file-2.2",
"file-2.3",
},
},
"table3": {files: []string{"file-3.1"}},
}
fmt.Printf("%#v\n", &object)
objectJSON, err := json.MarshalIndent(object, "", " ")
if err != nil {
log.Fatalf(err.Error())
}
fmt.Printf("%s\n", objectJSON)
}
https://go.dev/play/p/FRWZsfwgyNU
With this code, I'm only getting the first depth of my object:
&main.Container{"table1":(*main.Table)(0xc00005c020), "table2":(*main.Table)(0xc00005c040), "table3":(*main.Table)(0xc00005c060)}
{
"table1": {},
"table2": {},
"table3": {}
}
Program exited.