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
Newsletter
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
  • A Practical Pipeline for Identifying Sensitive Columns Before Test Data Masking
  • 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

Trending

  • When RabbitMQ Accepts a Message but Does Not Route It to a Queue
  • Integrating Apache Spark With Drools: A Loan Approval Demo
  • Production-Grade LLM Regression Testing: Contracts, Evals, and Quality Gates
  • PII Detection Before RAG Ingestion: Screening Documents in C#

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Jan. 14, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
16.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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
  • A Practical Pipeline for Identifying Sensitive Columns Before Test Data Masking
  • 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

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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