Byte output

Report a typo

Patrick has created a Go program that serializes the Dog struct using the json.Marshal() function.

Now he wants to print the serialized dogJSON in a humanly-readable format. Please help Patrick write the required additional code to do this.

Sample Input 1:

Bruno Maltese 1

Sample Output 1:

{"Name":"Bruno","Breed":"Maltese","Age":1}
Write a program in Go
package main

import (
"encoding/json"
"fmt"
"log"
)

type Dog struct {
Name string
Breed string
Age int
}

func main() {
// DO NOT modify the code block below:
var name, breed string
var age int
fmt.Scanln(&name, &breed, &age)

dog := Dog{Name: name, Breed: breed, Age: age}

dogJSON, err := json.Marshal(dog)
if err != nil {
log.Fatal(err)
}

// How can you print `dogJSON` in a humanly-readable format?
?
}
___

Create a free account to access the full topic