diff --git a/crates/mod-serde/src/lib.rs b/crates/mod-serde/src/lib.rs index 3ddcd4f3..cc55bb20 100644 --- a/crates/mod-serde/src/lib.rs +++ b/crates/mod-serde/src/lib.rs @@ -81,6 +81,12 @@ fn json_encode(lua: &Lua, value: LuaValue) -> mlua::Result { fn json_encode_pretty(lua: &Lua, value: LuaValue) -> mlua::Result { let value = materialize_to_lua_value(lua, value)?; + // This additional conversion to a json value causes any object types + // to become backed by a BTreeMap rather than lua's randomly ordered + // table type, so that the pretty print will show the keys in sorted order. + // We only do that for pretty printing because we don't usually want + // to bother with that additional overhead + let value = serde_json::to_value(&value).map_err(any_err)?; serde_json::to_string_pretty(&value).map_err(any_err) } diff --git a/docs/changelog/main.md b/docs/changelog/main.md index 6e913e45..c66dcda1 100644 --- a/docs/changelog/main.md +++ b/docs/changelog/main.md @@ -21,6 +21,10 @@ reported earlier and/or more frequently than in prior versions, but should result in less of an overall bottleneck in the triggering scenario. + * [kumo.serde.json_encode_pretty](../reference/kumo.serde/json_encode_pretty.md) + now outputs keys of json objects in sorted order. This means that utilities + such as `resolve-shaping-domain` will now output keys in sorted order as well. + ## Fixes * sources helper didn't allow creating empty egress pools