Encoding a slice with indentation

Report a typo

Serialize the fruits slice into the fruitsJSON variable using the json.MarshalIndent() function.

You must specify exactly 4 blank spaces as the indent parameter, and finally, print the fruitsJSON variable — remember to cast it as a string!

Sample Input 1:

apple pineapple grape

Sample Output 1:

[
    "apple",
    "pineapple",
    "grape"
]
Write a program in Go
package main

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

func main() {
// DO NOT delete the code block below, it populates the 'fruits' slice!
var f1, f2, f3 string
fmt.Scanln(&f1, &f2, &f3)
fruits := []string{f1, f2, f3}

// Remember to specify 4 blank spaces " " as the indent parameter below:
fruitsJSON, err := json.MarshalIndent(?, ?, ?)
if err != nil {
log.Fatal(err)
}
fmt.Println(?(?))
}
___

Create a free account to access the full topic