Remove empty keys

Apache 2.0

Remove mapping entries whose value is an empty object or array, such as those left behind by DeleteKey. Entries are removed from the inside out, so a chain of objects holding nothing but the removed entry is removed entirely. Array elements are left alone, since removing one shifts the indexes of its siblings.

org.openrewrite.json.RemoveEmptyKeys

Optional

A JsonPath expression bounding the cleanup. Keys it selects, and the keys nested within them, are eligible for removal. When omitted, the whole document is eligible.

A JsonPath expression letting removal continue outward past keys. A key this recipe empties is removed when cascadeTo selects it or nests it, so keys of $.spec.template with cascadeTo of $.spec goes on to remove spec once template is gone. Keys that were already empty outside keys are still left alone. When omitted, removal stops at the keys boundary.

mod run . --recipe=org.openrewrite.json.RemoveEmptyKeys

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.