Compact
Synopsis
Removes null values, empty strings, empty arrays, and empty objects recursively.
Schema
compact:
- description: <text>
- if: <script>
- ignore_failure: <boolean>
- on_failure: <processor[]>
- on_success: <processor[]>
- tag: <string>
- values: <array>
Configuration
Field | Required | Default | Description |
---|---|---|---|
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | See Handling Failures |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
tag | N | - | Identifier |
values | N | - | Array of values to be removed when found, in addition to empty fields |
Details
Empty fields include null values, empty strings, empty arrays []
, and empty objects {}
. This processor helps reduce the document size and improve readability by eliminating all the unnecessary fields.
note
The processor is particularly useful for cleaning up documents before storage or transmission, reducing storage space and network bandwidth usage.
Examples
Basic Usage
Remove empty fields from document... |
|
resulting in only non-empty fields: |
|
Nested Objects
Process nested objects recursively... |
|
removing empty fields at all levels: |
|
Remove Specific Values
Remove empty fields and... |
|
specific values: |
|
Conditional Execution
Compact only when a condition is met... |
|
only user documents are compacted: |
|