Skip to content

Allow specific keys to be excluded from flatten #1682

@benjamin-awd

Description

@benjamin-awd

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Use Cases

We often perform selective flattening for our payloads, meaning that we often need to exclude certain keys during the flattening operation. Currently this requires a somewhat verbose save/restore dance:

metadata = del(.metadata)
tags = del(.tags)

. = compact(flatten(., "_"))

.metadata = metadata
.tags = tags

This is also useful for downstream consumers that do not necessarily want to flatten specific fields and instead want to store them within a JSON record/column.

Attempted Solutions

No response

Proposal

Add an optional except parameter to flatten that accepts an array of key names to exclude from flattening:

. = compact(flatten(., "_", except: ["metadata", "tags"]))

Keys matching the except list would be preserved as-is while everything else is flattened normally.

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featureA value-adding code addition that introduce new functionality.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions