Encoding a map with indentation

Report a typo

Bart is a rebel programmer that doesn't like to follow standard code style conventions!

He wants to use the json.MarshalIndent() function to take the \t character as both prefix and indent, and then print the encoded and indented moviesJSON map.

Below is the code Bart has written so far:

Sample Input 1:

Shrek 2001 7.9

Sample Output 1:

{
		"rating": 7.9,
		"releaseYear": 2001,
		"title": "Shrek"
	}
Write a program in Go
package main

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

func main() {
// DO NOT delete! - This code block takes as an input the values for the 'movies' map:
var title string
var releaseYear int
var rating float64

fmt.Scanln(&title, &releaseYear, &rating)

songs := map[string]interface{}{
"title": title,
"releaseYear": releaseYear,
"rating": rating,
}

// Call the json.MarshalIndent() function below and pass
// The correct 'prefix' and 'indent' following Bart's request:
moviesJSON, err := json.?(songs, "?", "?")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(moviesJSON))
}
___

Create a free account to access the full topic