How to Lowercase JSON Key Names with JSON Marshal in Go

To lowercase JSON key names with JSON Marshal in Go, you can “add a json tag to each field in your struct, specifying the desired lowercase key name”.

package main

import (

type Person struct {
  FirstName string `json:"firstName"`
  LastName string `json:"lastName"`
  Age int `json:"age"`

func main() {
  psn := Person{
    FirstName: "Krunal",
    LastName: "Lathiya",
    Age: 30,

 // Marshal the Person struct into JSON
  jsonData, err := json.Marshal(psn)
    if err != nil {
      fmt.Println("Error marshaling JSON:", err)

  // Print the JSON data



In this example, we defined a Person struct with FirstName, LastName, and Age fields.

We added the json tags to each field to specify the desired lowercase JSON key names.

When we marshal the Person struct into JSON using json.Marshal(), the resulting JSON object will have lowercase key names as specified in the json tags.

That’s it.