← All Exercises

Go Reflection Basics

advancedgo~30min

Background

Reflection enables runtime type inspection and manipulation, used in serialization, validation, and ORM frameworks.

Problem

Write a Go function that uses reflection to extract all field names and JSON tags from a struct type.

Input

A struct value to inspect.

Output

A map of field name to JSON tag value.

Sample tests

Sample 1

Input: User{Name:"Alice", Age:30}
Expected: {"Name":"name","Age":"age"}

Your solution

Learning objective

Learn runtime type inspection with reflect, struct tag reading, and the performance implications.