Searching and Removing nested element in JSON payload without explicit check #284
-
The problem I'm trying to solve here is that, let's consider the given is my test payload
and I want to remove the field zip form .customer.shipping-address! Now I can solve this by simply doing * - zip inside of shipping-address, but that's in this data. What if the payload returns data in which the zip is nested inside .employee.shipping-address! This thing may not be used in real life scenario but in my organization we're making a template service that transforms one payload to another and does not pass any sensitive data to end user. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
So you want to remove some specific field regardless of where in the JSON it appears? You can do that by writing a recursive function that traverses the JSON and for any object it finds it traverses that object and skips any field with the given name. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I did it. Here's the code.
Do you think I can optimize it or is there any test case issues? Do let me know. |
Beta Was this translation helpful? Give feedback.
Thanks, I did it.
Here's the code.
Do you think I can optimize it or is there any test case issues? Do let me know.