# Custom YAML marshal/unmarshal with Go

DevFeed: [Custom YAML marshal/unmarshal with Go](<https://devfeed.tech/articles/custom-yaml-marshal-unmarshal-with-go-37734.md>)

Original publisher: [Read original article](<https://carlosbecker.com/posts/go-custom-marshaling/>)

Author: Carlos Alexandro Becker

Published: 2025-03-19T00:00:00Z

Content type: tutorial

Language: en

Sources: [Carlos Becker](<https://devfeed.tech/sources/carlos-becker.md>)

Topics: [YAML](<https://devfeed.tech/topics/yaml.md>), [Go](<https://devfeed.tech/topics/go.md>), [JSON](<https://devfeed.tech/topics/json.md>), [configuration](<https://devfeed.tech/topics/configuration.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [go](<https://devfeed.tech/tags/go.md>), [json](<https://devfeed.tech/tags/json.md>), [yaml](<https://devfeed.tech/tags/yaml.md>)

## AI overview

A tutorial on using custom marshaling and unmarshaling in Go to support backward-compatible YAML configuration fields that accept either a string or an array. It also explains how to preserve that representation when marshaling and apply the same approach to JSON.

## Source excerpt

string and []string can be the same thing...