diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
 # Changelog
 
+## [0.2.0.3] - 2023-01-01
+
+### Changed
+
+Use the `ToYaml` instance instead of the `ToJSON` instance when encoding to Yaml.
+This preserves the key order where `ToJSON` wouldn't.
+
 ## [0.2.0.2] - 2022-07-21
 
 ### Added
diff --git a/autodocodec-yaml.cabal b/autodocodec-yaml.cabal
--- a/autodocodec-yaml.cabal
+++ b/autodocodec-yaml.cabal
@@ -5,13 +5,13 @@
 -- see: https://github.com/sol/hpack
 
 name:           autodocodec-yaml
-version:        0.2.0.2
+version:        0.2.0.3
 synopsis:       Autodocodec interpreters for yaml
 homepage:       https://github.com/NorfairKing/autodocodec#readme
 bug-reports:    https://github.com/NorfairKing/autodocodec/issues
 author:         Tom Sydney Kerckhove
 maintainer:     syd@cs-syd.eu
-copyright:      2021 Tom Sydney Kerckhove
+copyright:      2021-2023 Tom Sydney Kerckhove
 license:        MIT
 license-file:   LICENSE
 build-type:     Simple
diff --git a/src/Autodocodec/Yaml.hs b/src/Autodocodec/Yaml.hs
--- a/src/Autodocodec/Yaml.hs
+++ b/src/Autodocodec/Yaml.hs
@@ -35,10 +35,11 @@
 import Autodocodec.Yaml.Schema
 import Data.ByteString
 import qualified Data.Yaml as Yaml
+import qualified Data.Yaml.Builder as Yaml
 
 -- | Encode a value as a Yaml 'ByteString' via its type's 'codec'.
 encodeYamlViaCodec :: HasCodec a => a -> ByteString
-encodeYamlViaCodec = Yaml.encode . Autodocodec
+encodeYamlViaCodec = Yaml.toByteString . Autodocodec
 
 -- | Parse a Yaml 'ByteString' using a type's 'codec'.
 eitherDecodeYamlViaCodec :: HasCodec a => ByteString -> Either Yaml.ParseException a
