diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp
index 276bad5c6429be3346e0b921cc1fb77e2c98370b..790cb2b960189aa21f0c2f0944aeb66b07cfe175 100644
--- a/components/common/cpp/src/configuration.cpp
+++ b/components/common/cpp/src/configuration.cpp
@@ -657,19 +657,16 @@ Configurable *ftl::config::configure(ftl::config::json_t &cfg) {
 
 // Remove all $ keys from json
 static void stripJSON(nlohmann::json &j) {
-	auto items = j.items();
-	for(auto i=items.begin(); i != items.end(); ) {
-		auto &el = *i;
-		if (el.key()[0] == '$') {
-			++i;
-			j.erase(el.key());
+	for (auto i=j.begin(); i != j.end(); ) {
+		if (i.key()[0] == '$') {
+			i = j.erase(i);
 			continue;
 		}
-        if (el.value().is_structured()) {
-            stripJSON(el.value());
+        if ((*i).is_structured()) {
+            stripJSON(*i);
         }
 		++i;
-    }
+	}
 }
 
 static std::atomic_bool doing_cleanup = false;