Returns a record with fields whose value is null removed.
drop_null_fields(x:record, field:field...) -> recordDescription
Section titled “Description”The drop_null_fields function returns a copy of x with every field whose
value is null removed. Without explicit selectors, every field is considered,
including fields nested inside record-typed values. With selectors, only the
named fields (and any fields nested within them) are considered for removal;
other null fields are preserved.
Unlike print_ndjson(strip_null_fields=true), the function never serializes
the record, so secret-typed values flow through unchanged and reach the sink
unredacted.
x: record
Section titled “x: record”The record from which to remove null fields.
field: field... (optional)
Section titled “field: field... (optional)”A comma-separated list of field paths inside x to consider. When omitted,
every field is considered.
Examples
Section titled “Examples”Drop all null fields
Section titled “Drop all null fields”from { id: 42, status: "active", comment: null,}this = drop_null_fields(this){ id: 42, status: "active",}Build an HTTP request body inline
Section titled “Build an HTTP request body inline”A common use case is cleaning optional null fields out of an inline body
record before sending it to an API that rejects JSON null values:
from_http "https://api.example.com/v1/lookup", method="POST", body=drop_null_fields({ version: 1, query: "example", options: null, })The wire body contains only version and query; options is omitted.
Restrict the drop to specific fields
Section titled “Restrict the drop to specific fields”from { a: null, b: null, c: null, d: 1,}this = drop_null_fields(this, a, c){ b: null, d: 1,}b stays in the result because it was not named in the selector list, even
though it is null.
Recursive drop inside nested records
Section titled “Recursive drop inside nested records”from { metadata: { created: "2024-01-01", updated: null, }, data: { value: 42, comment: null, },}this = drop_null_fields(this){ metadata: { created: "2024-01-01", }, data: { value: 42, },}