Back to articles
Recursive PII Masking in DataWeave: One Function for Any Depth (and the Null Trap)

Recursive PII Masking in DataWeave: One Function for Any Depth (and the Null Trap)

via Dev.toThaSha

A compliance audit found SSN values 4 levels deep in our API responses last year. One recursive function masks everything. Then null values in production crashed 400 responses. TL;DR Recursive maskPII function dispatches on type: Object → check fields, Array → recurse, Primitive → pass through Works at any nesting depth with one function call: maskPII(payload) Null values crash it — add explicit null handling before the Object case No hardcoded paths needed — the function finds PII fields at any level The Problem: PII at Unknown Depth Our org chart API returns hierarchical data: { "company" : "Acme Corp" , "ceo" : { "name" : "Alice Chen" , "ssn" : "123-45-6789" , "email" : "alice@acme.com" , "reports" : [ { "name" : "Bob Martinez" , "ssn" : "234-56-7890" , "email" : "bob@acme.com" , "reports" : [ { "name" : "Carol Nguyen" , "ssn" : "345-67-8901" } ] } ] } } SSN at level 1 (CEO), level 2 (VP), level 3 (Director). The compliance requirement: mask ALL of them. The depth varies per org — s

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles