diff --git a/ChangeLog.md b/ChangeLog.md
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,5 +1,9 @@
 # ChangeLog for yaml
 
+## 0.11.9.0
+
+* Data.Yaml.Pretty: provide key-sorting function with path to parent object [#206](https://github.com/snoyberg/yaml/pull/206)
+
 ## 0.11.8.0
 
 * Export `Parse` and `StringStyle` [#204](https://github.com/snoyberg/yaml/pull/204)
diff --git a/src/Data/Yaml/Pretty.hs b/src/Data/Yaml/Pretty.hs
--- a/src/Data/Yaml/Pretty.hs
+++ b/src/Data/Yaml/Pretty.hs
@@ -7,6 +7,7 @@
     , Config
     , getConfCompare
     , setConfCompare
+    , setConfComparePos
     , getConfDropNull
     , setConfDropNull
     , defConfig
@@ -50,7 +51,7 @@
 -- |
 -- @since 0.8.13
 data Config = Config
-  { confCompare :: Text -> Text -> Ordering -- ^ Function used to sort keys in objects
+  { confCompare :: JSONPath -> Text -> Text -> Ordering -- ^ Function used to sort keys in objects
   , confDropNull :: Bool -- ^ Drop null values from objects
   }
 
@@ -62,15 +63,21 @@
 
 -- |
 -- @since 0.8.13
-getConfCompare :: Config -> Text -> Text -> Ordering
+getConfCompare :: Config -> JSONPath -> Text -> Text -> Ordering
 getConfCompare = confCompare
 
 -- | Sets ordering for object keys
 --
 -- @since 0.8.13
 setConfCompare :: (Text -> Text -> Ordering) -> Config -> Config
-setConfCompare cmp c = c { confCompare = cmp }
+setConfCompare cmp c = c { confCompare = \_ps -> cmp }
 
+-- | Set ordering for object keys that depends on location of object in the document.
+--
+-- @since 0.11.9
+setConfComparePos :: (JSONPath -> Text -> Text -> Ordering) -> Config -> Config
+setConfComparePos cmp c = c { confCompare = cmp }
+
 -- |
 -- @since 0.8.24
 getConfDropNull :: Config -> Bool
@@ -83,17 +90,17 @@
 setConfDropNull m c = c { confDropNull = m }
 
 pretty :: Config -> Value -> YamlBuilder
-pretty cfg = go
-  where go (Object o) = let sort = sortBy (confCompare cfg `on` fst)
-                            select
-                              | confDropNull cfg = HM.filter (/= Null)
-                              | otherwise        = id
-                        in mapping (sort $ fmap (first toText) $ HM.toList $ HM.map go $ select o)
-        go (Array a)  = array (go <$> V.toList a)
-        go Null       = null
-        go (String s) = string s
-        go (Number n) = scientific n
-        go (Bool b)   = bool b
+pretty cfg = go []
+  where go ps (Object o) = let sort = sortBy (confCompare cfg (reverse ps) `on` fst)
+                               select
+                                 | confDropNull cfg = HM.filter (/= Null)
+                                 | otherwise        = id
+                        in mapping (sort $ fmap (first toText) $ HM.toList $ HM.mapWithKey (\k -> go (Key (toText k): ps)) $ select o)
+        go ps (Array a) = array $ zipWith (\ix -> go (Index ix: ps)) [0..] (V.toList a)
+        go _ Null       = null
+        go _ (String s) = string s
+        go _ (Number n) = scientific n
+        go _ (Bool b)   = bool b
 
 -- | Configurable 'encode'.
 --
diff --git a/yaml.cabal b/yaml.cabal
--- a/yaml.cabal
+++ b/yaml.cabal
@@ -1,11 +1,11 @@
 cabal-version: 1.12
 
--- This file has been generated from package.yaml by hpack version 0.34.4.
+-- This file has been generated from package.yaml by hpack version 0.35.1.
 --
 -- see: https://github.com/sol/hpack
 
 name:           yaml
-version:        0.11.8.0
+version:        0.11.9.0
 synopsis:       Support for parsing and rendering YAML documents.
 description:    README and API documentation are available at <https://www.stackage.org/package/yaml>
 category:       Data
@@ -74,7 +74,7 @@
     , filepath
     , libyaml ==0.1.*
     , mtl
-    , resourcet >=0.3 && <1.3
+    , resourcet >=0.3 && <1.4
     , scientific >=0.3
     , template-haskell
     , text
@@ -103,20 +103,20 @@
     , filepath
     , libyaml ==0.1.*
     , mtl
-    , resourcet >=0.3 && <1.3
+    , resourcet >=0.3 && <1.4
     , scientific >=0.3
     , template-haskell
     , text
     , transformers >=0.1
     , unordered-containers
     , vector
+  default-language: Haskell2010
   if flag(no-examples)
     buildable: False
   else
     build-depends:
         raw-strings-qq
       , yaml
-  default-language: Haskell2010
 
 executable json2yaml
   main-is: json2yaml.hs
@@ -138,7 +138,7 @@
     , libyaml ==0.1.*
     , mtl
     , optparse-applicative
-    , resourcet >=0.3 && <1.3
+    , resourcet >=0.3 && <1.4
     , scientific >=0.3
     , template-haskell
     , text
@@ -146,9 +146,9 @@
     , unordered-containers
     , vector
     , yaml
+  default-language: Haskell2010
   if flag(no-exe)
     buildable: False
-  default-language: Haskell2010
 
 executable yaml2json
   main-is: yaml2json.hs
@@ -174,7 +174,7 @@
     , libyaml ==0.1.*
     , mtl
     , optparse-applicative
-    , resourcet >=0.3 && <1.3
+    , resourcet >=0.3 && <1.4
     , scientific >=0.3
     , template-haskell
     , text
@@ -182,9 +182,9 @@
     , unordered-containers
     , vector
     , yaml
+  default-language: Haskell2010
   if flag(no-exe)
     buildable: False
-  default-language: Haskell2010
 
 test-suite spec
   type: exitcode-stdio-1.0
@@ -214,7 +214,7 @@
     , mockery
     , mtl
     , raw-strings-qq
-    , resourcet >=0.3 && <1.3
+    , resourcet >=0.3 && <1.4
     , scientific >=0.3
     , template-haskell
     , temporary
