DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Anypoint Mulesoft Masking Sensitive Data With DataWeave Custom Function in Logging
  • Stop Poisoning Your Models: How I Built a CV Dataset Quality Toolkit I Can Reuse Forever
  • Advanced Auto Loader Patterns for Large-Scale JSON and Semi-Structured Data
  • From 13,000 to 20,000+ Endpoints: Architecting Forensics for the Remote Workforce

Trending

  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  • No More Cheap Claude: 4 First Principles of Token Economics in 2026
  • Throughput vs Goodput: The Performance Metric You Are Probably Ignoring in LLM Testing
  • Why Your QA Engineer Should Be the Most Stubborn Person on the Team
  1. DZone
  2. Data Engineering
  3. Data
  4. Masking Data With MuleSoft DataWeave

Masking Data With MuleSoft DataWeave

Learn how to keep data private with DataWeave.

By 
Jitendra Bafna user avatar
Jitendra Bafna
·
Jan. 14, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
16.2K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we will see various examples of how we can mask data using MuleSoft DataWeave. MuleSoft DataWeave has a helper function, mask, in the DW Utils Values module.

We will be using the payload below to understand the mask function.

JSON
 




x


 
1
 [
2
      {
3
        "id": "1",
4
        "firstName": "Tom",
5
        "lastName": "Cruise",
6
        "age":25,
7
        "salary":20000
8
      },
9
      {
10
        "id": "2",
11
        "firstName": "Maria",
12
        "lastName": "Sharapova",
13
        "age":28,
14
        "salary":10000
15
      },
16
      {
17
        "id": "3",
18
        "firstName": "James",
19
        "lastName": "Bond",
20
        "age":32,
21
        "salary":30000
22
      }
23
    ]


Example 1 - Mask the Age to "***" 

We need to mask the age to "***". To do this, we can use the mask function.

JSON
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
import * from dw::util::Values
3
output application/json
4
---
5
payload mask field("age") with "***"


Output:

JSON
 




x


 
1
[
2
  {
3
    "id": "1",
4
    "firstName": "Tom",
5
    "lastName": "Cruise",
6
    "age": "***",
7
    "salary": 20000
8
  },
9
  {
10
    "id": "2",
11
    "firstName": "Maria",
12
    "lastName": "Sharapova",
13
    "age": "***",
14
    "salary": 10000
15
  },
16
  {
17
    "id": "3",
18
    "firstName": "James",
19
    "lastName": "Bond",
20
    "age": "***",
21
    "salary": 30000
22
  }
23
]


Example 2 - Mask the Age to "***" and Salary to "xxxx"

JSON
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
import * from dw::util::Values
3
output application/json
4
---
5
(payload mask field("age") with "***") mask field("salary") with "xxxx"


Output:

JSON
 




xxxxxxxxxx
1
23


 
1
[
2
  {
3
    "id": "1",
4
    "firstName": "Tom",
5
    "lastName": "Cruise",
6
    "age": "***",
7
    "salary": "xxxx"
8
  },
9
  {
10
    "id": "2",
11
    "firstName": "Maria",
12
    "lastName": "Sharapova",
13
    "age": "***",
14
    "salary": "xxxx"
15
  },
16
  {
17
    "id": "3",
18
    "firstName": "James",
19
    "lastName": "Bond",
20
    "age": "***",
21
    "salary": "xxxx"
22
  }
23
]


Example 3 - Format Salary to "$#,###.00"

JSON
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
import * from dw::util::Values
3
output application/json
4
type Currency= String{format:"\$#,###.00"}
5
---
6
payload mask field("salary") with $ as Currency


JSON
 




xxxxxxxxxx
1
23


 
1
[
2
  {
3
    "id": "1",
4
    "firstName": "Tom",
5
    "lastName": "Cruise",
6
    "age": 25,
7
    "salary": "$20,000.00"
8
  },
9
  {
10
    "id": "2",
11
    "firstName": "Maria",
12
    "lastName": "Sharapova",
13
    "age": 28,
14
    "salary": "$10,000.00"
15
  },
16
  {
17
    "id": "3",
18
    "firstName": "James",
19
    "lastName": "Bond",
20
    "age": 32,
21
    "salary": "$30,000.00"
22
  }
23
]


Example 4 - Convert FirstName and LastName to Uppercase

JSON
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
import * from dw::util::Values
3
output application/json
4
type Currency= String{format:"\$#,###.00"}
5
---
6
(payload mask field("firstName") with upper($)) mask field("lastName") with upper($)


Output:

JSON
 




xxxxxxxxxx
1
23


 
1
[
2
  {
3
    "id": "1",
4
    "firstName": "TOM",
5
    "lastName": "CRUISE",
6
    "age": 25,
7
    "salary": 20000
8
  },
9
  {
10
    "id": "2",
11
    "firstName": "MARIA",
12
    "lastName": "SHARAPOVA",
13
    "age": 28,
14
    "salary": 10000
15
  },
16
  {
17
    "id": "3",
18
    "firstName": "JAMES",
19
    "lastName": "BOND",
20
    "age": 32,
21
    "salary": 30000
22
  }
23
]


Now, you know how to mask data with MuleSoft DataWeave.

MuleSoft Data (computing) JSON Masking (Electronic Health Record)

Opinions expressed by DZone contributors are their own.

Related

  • Anypoint Mulesoft Masking Sensitive Data With DataWeave Custom Function in Logging
  • Stop Poisoning Your Models: How I Built a CV Dataset Quality Toolkit I Can Reuse Forever
  • Advanced Auto Loader Patterns for Large-Scale JSON and Semi-Structured Data
  • From 13,000 to 20,000+ Endpoints: Architecting Forensics for the Remote Workforce

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook