These Go standard library questions cover fmt, strings, strconv, os, io, bufio, encoding/json, time, slog and flag. We gathered them from public interview lists, coding rounds and community threads. Then we rewrote them in plain words and grouped them by package.
This post is questions only, so answer each one in your own words first. When you need help, read Go JSON encoding and decoding, Go file handling with examples and Go time package examples. Also, finish Part 11 on generics first, because the slices and maps packages use generics.
How to Use These Go Standard Library Questions
Answer each of these Go standard library questions out loud, then open the package docs and check one detail. Interviewers like this area because the standard library is large, yet most teams use the same few packages. Finally, try the scenario questions, since they come from real projects.
The table below lists each section and its number of questions.
| Section | What it tests | Questions |
|---|---|---|
| Text helpers | fmt, strings and strconv | 15 |
| Files and I/O | os, io and bufio | 16 |
| JSON | Struct tags, Marshal and Decoder | 16 |
| Time | Format, Duration and timers | 15 |
| More packages | slog, flag, os, sort, regexp and http | 15 |
| Standard library coding tasks | Classic interview programs | 13 |

Go Standard Library Questions on Text Helpers
Before you answer, study Go strings explained with examples. These Go standard library questions start with text, because almost every program prints or parses strings.
- What is the difference between fmt.Print, fmt.Println and fmt.Printf?
- Which verbs do %v, %+v and %#v print for a struct?
- How do %T and %q help when you debug a value?
- When would you use fmt.Sprintf, and when is strconv faster?
- How does strconv.Atoi differ from strconv.ParseInt?
- What error does strconv return for the text 12a, and how do you check it?
- Why should you build long strings with strings.Builder instead of + in a loop?
- How do strings.Split and strings.Fields differ on extra spaces?
- Which function trims spaces from both ends of a string?
- How do strings.Contains, strings.HasPrefix and strings.Index help in parsing?
- What does strings.NewReplacer do, and when is it better than many Replace calls?
- How does strings.EqualFold compare text without caring about case?
- Why is fmt.Fprintf useful with any io.Writer, for example a file or a buffer?
- Scenario: when a log shows a struct as {1 Asha true}, how would you print the field names too?
- Scenario: when a CSV import fails on numbers such as 1,250, how would you parse them safely?
Go Standard Library Questions on Files and I/O
Before you answer, study Go file handling with examples and Go reader and writer interfaces. These Go standard library questions check how you read and write data without wasting memory.
- How do os.ReadFile and os.Open differ, so when would you pick each?
- Why should you call defer f.Close right after a successful os.Open?
- Why does Close on a written file return an error that you should check?
- What flags does os.OpenFile take, for example to append to a log file?
- How does bufio.Scanner read a file line by line?
- What happens when a line is longer than the default Scanner buffer?
- When would you use bufio.Reader instead of bufio.Scanner?
- Why does bufio.Writer need a Flush call at the end?
- What does io.Copy do, and why does it use little memory?
- How do io.ReadAll and io.LimitReader work together to block huge inputs?
- What are io.TeeReader and io.MultiWriter used for?
- How do you walk every file in a folder, for example with filepath.WalkDir?
- Why should you use filepath.Join instead of joining paths with a slash?
- How do you write a file safely so that a crash never leaves half a file, for example with a temp file and rename?
- Scenario: when a service reads a 4 GB log file with os.ReadFile and runs out of memory, how would you change it?
- Scenario: when a report file is empty even though the code wrote to it, what would you check first?
Go Standard Library Questions on JSON
Before you answer, study Go JSON encoding and decoding. Almost every Go backend speaks JSON, so these Go standard library questions appear in most backend interviews.
- How do json.Marshal and json.Unmarshal work with struct tags?
- What do the omitempty and dash options do in a json tag?
- What does the omitzero option add in Go 1.24, for example for time.Time?
- Why does the json package skip unexported fields?
- Which Go type does a JSON number become when you decode into any?
- How does Decoder.UseNumber help with large IDs?
- How do you reject unknown fields with Decoder.DisallowUnknownFields?
- What is json.RawMessage, and when would you delay decoding?
- How do you write a custom MarshalJSON method for a Money type?
- Why does the json package sometimes skip a MarshalJSON method with the wrong receiver kind?
- How does the json package treat a nil slice compared with an empty slice?
- How do you decode a JSON array of objects into a slice of structs?
- What happens when the JSON has a string where your struct expects an int?
- How does json.Indent or json.MarshalIndent help in logs and tests?
- Scenario: when a client sends a field with the wrong case, such as UserName instead of username, what does Go do?
- Scenario: when an API must accept a status as either a number or a string, how would you decode it?
Go Standard Library Questions on Time
Before you answer, study Go time package examples. Time bugs are hard to see in tests, so interviewers use these Go standard library questions to check your care with dates.
- What is the reference time in Go layouts, and why is it Mon Jan 2 15:04:05 MST 2006?
- How do you format a time as 2026-09-13 09:00?
- How do you parse a date string in a given time zone?
- What is time.Duration, and what unit does it store?
- Why does time.Sleep(5) sleep for five nanoseconds instead of five seconds?
- How do you compare two times, and why should you avoid == on time.Time?
- What is the monotonic clock reading, and how does it protect elapsed time math?
- How do time.Since and time.Until help in logs and timeouts?
- How do time.Timer and time.Ticker differ?
- Why must you call Stop on a Ticker you no longer need?
- What changed for unused timers and time.After in Go 1.23?
- How do you store times in a database in UTC and show them in local time?
- How do you make code that calls time.Now easy to test?
- Scenario: when a daily job runs twice on a daylight saving day, how would you fix the schedule?
- Scenario: when a token expiry check fails only on one server, what would you check about time?
More Standard Packages
Before you answer, study Go structured logging with slog and Go flag package. These Go standard library questions cover the smaller packages that still show up in real code reviews.
- What does log/slog add compared with the older log package?
- How do you add key value pairs to a slog record?
- Which handler switches slog from text output to JSON output?
- How does the flag package define and parse command line flags?
- How do you read an environment variable with a default value?
- What does os.Exit skip, and why should main avoid it after defers?
- How do slices.Sort and sort.Slice differ?
- When does sort.SliceStable matter for the final order?
- Why should you compile a regexp once instead of inside a loop?
- How does the http.Client default timeout behave, and why is it risky?
- What do bytes.Buffer and strings.Reader give you for tests?
- How does the embed package put files into a binary?
- Which package gives you crypto safe random numbers, and why not math/rand?
- Scenario: when a CLI tool must accept a config file path and a verbose flag, how would you build it?
- Scenario: when production logs are hard to search, how would you move a service to structured logs?
Go Standard Library Questions for Coding Rounds
Before you answer, write each program by hand with only the standard library. Interviewers watch which package you reach for, not only whether the code runs.
- Count how many times each word appears in a text file.
- Read a CSV file with encoding/csv and sum one column.
- Write a function that tails the last ten lines of a file.
- Parse a JSON config file into a struct with defaults.
- Convert a slice of structs into pretty printed JSON.
- Print the number of days between two dates.
- Write a tiny CLI that takes a name flag and prints a greeting.
- Merge two sorted files of numbers into one sorted file.
- Find all email addresses in a text with regexp.
- Copy a large file to another path with io.Copy and report the bytes.
- Log three events with slog in JSON format.
- Scenario: when an interviewer asks you to process a 10 GB file with little memory, how would you stream it?
- Scenario: when a JSON API returns times in different zones, how would you show them all in IST?
Code Reading Questions
Read each program carefully and predict the output before you run it. Then explain the result in your own words.
package main
import (
"encoding/json"
"fmt"
"time"
)
type Order struct {
ID int `json:"id"`
Items []string `json:"items,omitempty"`
Note string `json:"note,omitempty"`
Created time.Time `json:"created"`
}
func main() {
o := Order{ID: 7, Created: time.Date(2026, 9, 12, 9, 0, 0, 0, time.UTC)}
b, _ := json.Marshal(o)
fmt.Println(string(b))
var m map[string]any
_ = json.Unmarshal([]byte(`{"id": 7, "total": 250}`), &m)
fmt.Printf("%T %v\n", m["id"], m["total"])
var o2 Order
err := json.Unmarshal([]byte(`{"id": "seven"}`), &o2)
fmt.Println(err != nil, o2.ID)
}
- What JSON does the first line print, and why are items and note missing?
- Why does the id inside the map print as float64, and what happens with the text seven?
The second program mixes time layouts, durations and strings.Builder.
package main
import (
"fmt"
"strings"
"time"
)
func main() {
t := time.Date(2026, time.September, 12, 21, 5, 0, 0, time.UTC)
fmt.Println(t.Format("2006-01-02 15:04"))
fmt.Println(t.Format("02 Jan 2006, 3:04 PM"))
d := 90 * time.Minute
fmt.Println(d, d.Hours())
next := t.Add(d)
fmt.Println(next.Format(time.Kitchen), next.Day())
var sb strings.Builder
for i := 3; i > 0; i-- {
fmt.Fprintf(&sb, "%d...", i)
}
fmt.Println(sb.String(), sb.Len())
}
- What does each Format call print, and why do the layouts use 2006 and 15?
- How does Go print the duration d, and what is the final length of the builder?
Quick Revision Table for the Standard Library
Use the table below as a final check before your interview. It maps common tasks to the package that solves them.
| Task | Package | Key function or type |
|---|---|---|
| Read a file line by line | bufio | Scanner |
| Copy a stream with little memory | io | Copy |
| Turn structs into JSON | encoding/json | Marshal, Encoder |
| Measure elapsed time | time | Since, Duration |
| Write structured logs | log/slog | Info, JSONHandler |
| Read command line options | flag | String, Int, Parse |
Also, many interviewers ask you to compare the two JSON decoding styles directly. The diagram below shows the difference side by side.

Official Resources
These official pages explain the rules behind these questions.
- Go standard library index
- Package encoding/json documentation
- Package time documentation
- Go blog: Structured Logging with slog
Quick Recap
- These Go standard library questions cover text helpers, files, JSON, time, smaller packages and coding tasks.
- Stream large files with bufio and io.Copy instead of reading them whole.
- JSON uses struct tags, skips unexported fields and decodes numbers into float64 inside any.
- Go time layouts use the reference date Mon Jan 2 15:04:05 MST 2006.
- Use slog for structured logs and flag for simple command line tools.
- Check the error from Close when you write a file.
What’s Next?
By now, you have Go standard library questions for the packages that interviewers ask about most. Study the answers in your own notes, then check them against the Go interview topics study guide.


