I need to mask the following JSON data : given JSON:
{
"key1":"value1",
"key2":"value2",
"key3": {
"key4":"value3"
}
}
Maksed data :
{
"key1":"value1",
"key2":"value2",
"key3": {
"key4":"000000"
}
}
we already have a question JSON PII data masking in Java whoes answer works if the key is part of the main response(for example key1 , key2 or key3) , but i need something for nested values. (using jackson)
What if we have the json property name's that we need to mask but its position can differ in JSON depending on the response received. How to mask such values? Example : I only know that I need to mask "key4" value.
you already have the answer. Jackson will create a Map
for every nested property. You can use the answer from previous question and just change the process of the map
// Process map
if (map.containsKey("key3")) {
Map<String, Object> nestedMap = (Map<String, Object>)map.get("key3");
if (nestedMap.containsKey("key4")) {
nestedMap.put("key4","000000");
}
}