I was able to create a data masking policy for a json column for the top level keys with the following, but couldn't figure out to go to deeper layers in json. Anybody has done that?
CREATE OR REPLACE MASKING POLICY json_mask_test AS
(val variant) returns variant ->
CASE
WHEN invoker_role()='ADMIN' THEN val
ELSE object_insert(
object_insert(
object_insert(val, 'pii_field', '***', true),
'address','***', true),
'lastName','***', true)
END
If object_insert
is the only way to create a masking policy on a json field, looks like it's limited to top level keys.
I was using the example for On Variant Data
Also as a side effect this policy inserts the keys into the json fields when the keys don't exist in original field. To be able to eliminate this would be desirable.
Edit:
I have used this json for the example above
{"regular_field": "regular data", "pii_field": "pii data"}
I was trying to mask LastNames in a json like the following
'{"root":[{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}]}'