Skip to main content

Mastering DataWeave: A Comprehensive Guide

 

Course Outline:

Module 1: Introduction to DataWeave

1.1 What is DataWeave?

  • Introduction to DataWeave as a transformation language
  • Why DataWeave is important in MuleSoft integration

1.2 DataWeave Basics

  • Syntax and data types in DataWeave
  • Variables and functions in DataWeave
  • Working with literals and expressions

1.3 DataWeave Functions

  • Overview of built-in functions
  • Using functions for string manipulation, math operations, and date/time formatting

Module 2: DataWeave Transformations

2.1 Simple Data Transformations

  • Transforming JSON, XML, and CSV data
  • Handling arrays and objects in DataWeave

2.2 Complex Transformations

  • Nesting and flattening data structures
  • Filtering and mapping data elements
  • Handling null and default values

Module 3: Advanced DataWeave Concepts

3.1 Error Handling in DataWeave

  • Dealing with errors and exceptions in transformations
  • Using try-catch blocks for error handling

3.2 Streaming Data with DataWeave

  • Understanding streaming in DataWeave
  • Implementing streaming transformations for large datasets

Module 4: DataWeave Best Practices

4.1 Performance Optimization

  • Optimizing DataWeave transformations for speed and efficiency
  • Avoiding common performance pitfalls

4.2 Reusability and Modularity

  • Creating reusable DataWeave modules
  • Best practices for maintaining modular and scalable transformations

Module 5: Real-world Applications

5.1 Data Integration Scenarios

  • Integrating with RESTful APIs using DataWeave
  • Transforming data for database operations
  • Handling file-based data with DataWeave

5.2 Case Studies and Projects

  • Real-world case studies demonstrating DataWeave usage in different industries
  • Hands-on projects for students to apply their knowledge

Module 6: Testing and Debugging DataWeave Transformations

6.1 Unit Testing DataWeave Code

  • Writing test cases for DataWeave transformations
  • Using MUnit for testing DataWeave code

6.2 Debugging DataWeave Transformations

  • Debugging techniques and tools for DataWeave
  • Common debugging scenarios and solutions

Module 7: Best Practices and Optimization

7.1 Coding Standards and Best Practices

  • Establishing coding standards for DataWeave
  • Code review practices for DataWeave transformations

7.2 Performance Optimization Techniques

  • Profiling and optimizing DataWeave code for speed and resource efficiency
  • Strategies for optimizing large and complex transformations

Module 8: DataWeave in Real-time Scenarios

8.1 Real-time Data Processing

  • Implementing real-time data processing using DataWeave
  • Integrating DataWeave with streaming platforms

8.2 Advanced Integrations

  • Working with external libraries and modules in DataWeave
  • Integrating DataWeave with third-party APIs and services

Module 9: Future Trends and Advanced Concepts

9.1 Future Trends in DataWeave

  • Exploring the future of DataWeave and data integration technologies
  • Predictive analysis and AI-driven transformations

9.2 Advanced DataWeave Concepts

  • Custom functions and libraries in DataWeave
  • Exploring experimental and advanced features

Module 10: Capstone Project

10.1 Capstone Project Description

  • Overview of the final project
  • Requirements and guidelines for the project

10.2 Project Implementation

  • Hands-on implementation of the capstone project using DataWeave
  • Project presentation and evaluation

    Introduction to DataWeave

    DataWeave is a powerful, expressive, and versatile transformation language provided by MuleSoft, a leading integration platform. It is used for transforming data from one format to another within Mule applications. DataWeave operates on various data structures, such as JSON, XML, and CSV, allowing seamless transformation between different data formats. It is a fundamental part of MuleSoft's Anypoint Platform, enabling developers to manipulate and transform data with ease.

    Key Features of DataWeave:

    1. Declarative Language: DataWeave is a declarative language, meaning you define the desired output structure and transformation logic without specifying the step-by-step procedure. This makes it concise and easy to understand.

    2. Unified Syntax: DataWeave provides a unified syntax for working with different data formats, simplifying the transformation process. Whether you are dealing with JSON, XML, or CSV, DataWeave syntax remains consistent, reducing the learning curve.


    3. Functional Programming Paradigm: DataWeave adopts functional programming concepts, allowing developers to use higher-order functions, map, filter, and reduce operations. This functional approach promotes readability and maintainability of transformations.


    4. Broad Data Type Support: DataWeave supports various data types, including strings, numbers, arrays, objects, and even custom data types. This versatility enables complex transformations and data manipulations.


    5. Extensive Standard Library: DataWeave comes with a rich set of built-in functions, covering tasks such as string manipulation, date formatting, mathematical operations, and more. These functions simplify common transformation challenges.


    6. Error Handling: DataWeave provides robust error handling mechanisms, allowing developers to handle exceptions, errors, and edge cases effectively. This ensures that transformations are reliable and fault-tolerant.


    7. Streaming Capabilities: DataWeave supports streaming, enabling the processing of large datasets without consuming excessive memory. It efficiently handles data in a streaming fashion, ensuring optimal performance.

    Common Use Cases for DataWeave:

    1. Data Integration: DataWeave is widely used for integrating disparate systems by transforming data formats between APIs, databases, and applications. It plays a crucial role in harmonizing data structures during integration processes.


    2. Data Enrichment: DataWeave can enrich data by merging information from multiple sources. For example, it can combine customer data from a CRM system with order details from an e-commerce platform, creating a comprehensive dataset.


    3. Data Validation and Cleansing: DataWeave helps in validating incoming data and cleansing it by removing inconsistencies, duplicates, or errors. It ensures that the data meets the required standards before further processing.


    4. Data Aggregation: DataWeave can aggregate data from various sources, performing calculations, summarizations, and aggregations. It is useful for generating reports and insights from diverse datasets.


    5. Data Transformation for APIs: When building APIs, DataWeave transforms data into the expected format for request and response payloads. It ensures seamless communication between API consumers and providers.


1. DataWeave Syntax:

DataWeave uses a concise and expressive syntax for data transformation. It operates on various data types such as strings, numbers, arrays, objects, and custom data structures. Here are some basic elements of DataWeave syntax:

  • Strings: Strings are enclosed in double quotes.

    arduino
    "Hello, World!"

  • Numbers: Numbers can be integers or decimals.

    42 3.14

  • Arrays: Arrays are ordered collections of elements.

    csharp
    [1, 2, 3, 4, 5]

  • Objects: Objects are collections of key-value pairs.

    json
    { "name": "John", "age": 30, "city": "New York" }

2. Variables and Assignments:


DataWeave allows you to store values in variables for reuse within the script.

dw
var greeting = "Hello, World!" --- greeting

3. DataWeave Operators:

  • Arithmetic Operators: +, -, *, /, % (Addition, Subtraction, Multiplication, Division, Modulus)

  • Comparison Operators: ==, !=, <, >, <=, >= (Equal, Not Equal, Less Than, Greater Than, Less Than or Equal, Greater Than or Equal)

  • Logical Operators: and, or, not (Logical AND, Logical OR, Logical NOT)

4. Data Types and Type Casting:

DataWeave supports various data types such as strings, numbers, arrays, and objects. You can perform type casting using the as keyword.

dw
var age = "30" as Number

5. Accessing Array and Object Elements:

  • Accessing Array Elements:

    dw
    var numbers = [1, 2, 3, 4, 5] var secondNumber = numbers[1]
  • Accessing Object Properties:

    dw
    var person = { "name": "Alice", "age": 25 } var personName = person.name

6. Functions and Transformations:

DataWeave provides various built-in functions for data manipulation. You can also create custom functions for specific requirements.

dw
var inputString = "hello world" var upperCaseString = upper(inputString) --- upperCaseString

7. Conditional Logic:

DataWeave supports if-else statements for conditional logic.

dw
var age = 18 var message = if (age >= 18) "You are an adult" else "You are a minor" --- message

8. Mapping and Filtering Arrays:

DataWeave provides map and filter functions for working with arrays.

dw
var numbers = [1, 2, 3, 4, 5] var squaredNumbers = numbers map ((num) -> num * num)

9. Handling Null Values:

DataWeave includes the null keyword to represent absence of data. You can use the null coalescing operator default to handle null values.

dw
var name = payload.name default "Unknown"

10. Escaping Characters:

DataWeave allows you to escape special characters using backslashes (\).

dw
var stringWithQuotes = "He said, \"Hello!\""

Functions:

DataWeave provides a wide range of built-in functions for manipulating and transforming data. Here is an overview of some commonly used DataWeave functions categorized by their functionalities:

1. String Functions:

  • upper(str: String): Converts a string to uppercase.
  • lower(str: String): Converts a string to lowercase.
  • capitalize(str: String): Capitalizes the first letter of a string.
  • splitBy(str: String, delimiter: String): Splits a string into an array based on a specified delimiter.
  • replace(str: String, target: String, replacement: String): Replaces occurrences of a substring with another string.
  • contains(str: String, substring: String): Checks if a string contains a specific substring.

2. Number Functions:

  • round(number: Number): Rounds a number to the nearest integer.
  • floor(number: Number): Rounds a number down to the nearest integer.
  • ceil(number: Number): Rounds a number up to the nearest integer.
  • abs(number: Number): Returns the absolute value of a number.
  • random(): Generates a random float between 0 and 1.

3. Array Functions:

  • map(arr: Array, (item: Any) -> Any): Applies a transformation to each element of an array.
  • filter(arr: Array, (item: Any) -> Boolean): Filters an array based on a specified condition.
  • reduce(arr: Array, (acc: Any, item: Any) -> Any): Reduces an array to a single value based on a specified operation.
  • pluck(arr: Array, key: String): Extracts the values of a specific property from an array of objects.

4. Object Functions:

  • keys(obj: Object): Returns an array of keys from an object.
  • values(obj: Object): Returns an array of values from an object.
  • merge(obj1: Object, obj2: Object): Merges two objects into a single object.
  • pick(obj: Object, key: String): Retrieves the value of a specific key from an object.

5. Date and Time Functions:

  • now(): Returns the current date and time.
  • dateOf(dateString: String, format: String): Parses a string into a date object based on the specified format.
  • format(date: Date, format: String): Formats a date object into a string based on the specified format.

6. Type Conversion Functions:

  • number(str: String): Converts a string to a number.
  • string(value: Any): Converts a value to a string.
  • boolean(value: Any): Converts a value to a boolean.

7. Other Common Functions:

  • sizeOf(obj: Any): Returns the size or length of an object, array, or string.
  • isEmpty(value: Any): Checks if a value is empty or null.
  • default(value: Any, defaultValue: Any): Returns a default value if the input value is null or empty.

These functions represent just a subset of the available DataWeave functions. For more detailed information and examples, you can refer to the official MuleSoft documentation or experiment with these functions in your own DataWeave scripts. Practice and experimentation are key to mastering the usage of these functions in various data transformation scenarios.


DataWeave transformations in MuleSoft are used to manipulate and transform data from one format to another. DataWeave provides a rich set of functions and operators to perform complex transformations with ease. Here are some common DataWeave transformations you might encounter:

1. Basic Data Transformations:

Mapping Data:

Mapping data from one object structure to another using the map function:

dw
%dw 2.0 output application/json --- { id: payload.userId, name: payload.firstName ++ " " ++ payload.lastName }

Filtering Data:

Filtering an array of objects based on a condition using the filter function:

dw
%dw 2.0 output application/json --- payload filter (user) -> user.age > 18

2. Handling Null Values:

Default Values:

Setting default values for properties that might be null or missing:

dw
%dw 2.0 output application/json --- { id: payload.userId default 0, name: payload.name default "Unknown" }

3. Working with Arrays:

Flattening Arrays:

Flattening nested arrays into a single array using the flatten function:

dw
%dw 2.0 output application/json --- flatten(payload)

Joining Arrays:

Joining multiple arrays into a single array using the ++ operator:

dw
%dw 2.0 output application/json --- payload1 ++ payload2

4. Date and Time Transformations:

Formatting Dates:

Formatting dates into a specific format using the format function:

dw
%dw 2.0 output application/json --- { formattedDate: now() as String { format: "yyyy-MM-dd'T'HH:mm:ssZ" } }

5. Advanced Transformations:

Grouping Data:

Grouping data based on a common property using the groupBy function:

dw
%dw 2.0 output application/json --- payload groupBy (item) -> item.category

Using Reduce Function:

Using the reduce function to aggregate data into a single value:

dw
%dw 2.0 output application/json --- payload reduce ((acc, item) -> acc + item.amount) // Sums up 'amount' property of objects in the array

6. Conditional Transformations:

Conditional Mapping:

Mapping data conditionally based on a specific condition:

dw
%dw 2.0 output application/json --- { result: if (payload.score >= 50) "Pass" else "Fail" }

7. Error Handling:

Try-Catch Blocks:


Handling errors using try-catch blocks:


dw
%dw 2.0 output application/json --- try { // Data transformation logic } catch (error) { { error: error as String } }

These examples provide a glimpse into the various types of transformations you can perform with DataWeave. DataWeave's flexibility and rich feature set make it a powerful tool for data manipulation and integration tasks within MuleSoft applications. For more complex transformations and specific use cases, you can refer to the official MuleSoft documentation or experiment with DataWeave in your Mule projects.


Simple Data Transformations:


1. JSON to JSON Transformation:

Scenario:

You have JSON data containing user information, and you want to transform it into a simplified format.

Input JSON:

json
{ "user": { "id": 1, "name": "John Doe", "email": "john.doe@example.com" } }

DataWeave Transformation:

dw
%dw 2.0 output application/json --- { userId: payload.user.id, userName: payload.user.name }

Output JSON:

json
{ "userId": 1, "userName": "John Doe" }

2. XML to JSON Transformation:

Scenario:

You have XML data representing products, and you want to transform it into JSON format.

Input XML:

xml
<products> <product> <id>101</id> <name>Product A</name> <price>49.99</price> </product> <product> <id>102</id> <name>Product B</name> <price>29.95</price> </product> </products>

DataWeave Transformation:

dw
%dw 2.0 output application/json --- payload.products.product map ((product) -> { productId: product.id, productName: product.name, productPrice: product.price })

Output JSON:

json
[ { "productId": "101", "productName": "Product A", "productPrice": "49.99" }, { "productId": "102", "productName": "Product B", "productPrice": "29.95" } ]

3. CSV to JSON Transformation:

Scenario:

You have CSV data containing customer information, and you want to transform it into JSON format.

Input CSV:

graphql
id,name,email 1,Alice,a@example.com 2,Bob,b@example.com 3,Charlie,c@example.com

DataWeave Transformation:

dw
%dw 2.0 output application/json --- payload splitBy "\n" map ((row, index) -> if (index > 0) { var columns = row splitBy "," { id: columns[0] as Number, name: columns[1], email: columns[2] } } else null ) filter (customer) -> customer != null

Output JSON:

json
[ { "id": 1, "name": "Alice", "email": "a@example.com" }, { "id": 2, "name": "Bob", "email": "b@example.com" }, { "id": 3, "name": "Charlie", "email": "c@example.com" } ]



Complex Transformations

1. Nested JSON Transformation:

Scenario:

You have nested JSON data, and you want to flatten the structure and extract specific information.

Input JSON:

json
{ "user": { "id": 1, "name": { "first": "John", "last": "Doe" }, "address": { "city": "New York", "zip": "10001" } } }

DataWeave Transformation:

dw
%dw 2.0 output application/json --- { userId: payload.user.id, firstName: payload.user.name.first, lastName: payload.user.name.last, city: payload.user.address.city, zipCode: payload.user.address.zip }

Output JSON:

json
{ "userId": 1, "firstName": "John", "lastName": "Doe", "city": "New York", "zipCode": "10001" }

2. Conditional Transformation:

Scenario:

You have data containing a status field, and based on the status, you want to transform the data differently.

Input JSON:

json
{ "status": "active", "value": 100 }

DataWeave Transformation:

dw
%dw 2.0 output application/json --- if (payload.status == "active") { { isActive: true, amount: payload.value * 2 } } else { { isActive: false, amount: payload.value } }

Output JSON:

json
{ "isActive": true, "amount": 200 }

3. Aggregating Data:

Scenario:

You have multiple data sources, and you want to aggregate and transform the data into a single JSON object.

Input JSONs:

json
{ "user": { "id": 1, "name": "Alice" } }
json
{ "orders": [ { "id": 101, "product": "Product A" }, { "id": 102, "product": "Product B" } ] }

DataWeave Transformation:

dw
%dw 2.0 output application/json --- { userId: payload[0].user.id, userName: payload[0].user.name, orderIds: payload[1].orders map ((order) -> order.id), products: payload[1].orders map ((order) -> order.product) }

Output JSON:

json
{ "userId": 1, "userName": "Alice", "orderIds": [101, 102], "products": ["Product A", "Product B"] }

1. Filtering Data Elements:

Scenario:

You have an array of users, and you want to filter out the users who are older than 18 years.

Input JSON:

json
[ { "id": 1, "name": "Alice", "age": 25 }, { "id": 2, "name": "Bob", "age": 17 }, { "id": 3, "name": "Charlie", "age": 20 } ]

DataWeave Transformation:

dw
%dw 2.0 output application/json --- payload filter (user) -> user.age > 18

Output JSON:

json
[ { "id": 1, "name": "Alice", "age": 25 }, { "id": 3, "name": "Charlie", "age": 20 } ]

In this example, the filter function is used to keep only the users whose age is greater than 18.

2. Mapping Data Elements:

Scenario:

You have an array of products, and you want to create a new array containing only the product names.

Input JSON:

json
[ { "id": 101, "name": "Product A" }, { "id": 102, "name": "Product B" }, { "id": 103, "name": "Product C" } ]

DataWeave Transformation:

dw
%dw 2.0 output application/json --- payload map ((product) -> product.name)

Output JSON:

json
[ "Product A", "Product B", "Product C" ]

In this example, the map function is used to create a new array by extracting the name property from each product object in the input array.

3. Combining Filtering and Mapping:

Scenario:

You have an array of orders, and you want to filter out the completed orders and create a new array containing only the product names of those orders.

Input JSON:

json
[ { "id": 1, "status": "completed", "product": { "name": "Product A" } }, { "id": 2, "status": "pending", "product": { "name": "Product B" } }, { "id": 3, "status": "completed", "product": { "name": "Product C" } } ]

DataWeave Transformation:

dw
%dw 2.0 output application/json --- payload filter ((order) -> order.status == "completed") map ((order) -> order.product.name)

Output JSON:

json
[ "Product A", "Product C" ]

In this example, the filter function is used to keep only the orders with a status of "completed", and then the map function is used to create a new array containing the product names of those completed orders.

1. Handling Null Values:

Scenario:

You have an input JSON object with some properties that might be null, and you want to handle those null values gracefully.

Input JSON:

json
{ "id": 1, "name": null, "email": "john.doe@example.com" }

DataWeave Transformation:

dw
%dw 2.0 output application/json --- { userId: payload.id, userName: payload.name default "Unknown", userEmail: payload.email default "N/A" }

Output JSON:

json
{ "userId": 1, "userName": "Unknown", "userEmail": "john.doe@example.com" }

In this example, the default keyword is used to set default values for userName and userEmail properties if they are null in the input data.

2. Handling Default Values for Missing Properties:

Scenario:

You have an input JSON object where some properties might be missing, and you want to set default values for those missing properties.

Input JSON:

json
{ "id": 1 }

DataWeave Transformation:

dw
%dw 2.0 output application/json --- { userId: payload.id, userName: payload.name default "Unknown", userEmail: payload.email default "N/A" }

Output JSON:

json
{ "userId": 1, "userName": "Unknown", "userEmail": "N/A" }

In this example, if name and email properties are missing in the input JSON, the default keyword ensures default values are provided in the output.

3. Handling Null Values in Arrays:

Scenario:

You have an array of objects where some objects might have null values, and you want to handle those null values.

Input JSON:

json
[ { "id": 1, "name": "Alice", "email": null }, { "id": 2, "name": "Bob", "email": "bob@example.com" } ]

DataWeave Transformation:

dw
%dw 2.0 output application/json --- payload map ((user) -> { userId: user.id, userName: user.name default "Unknown", userEmail: user.email default "N/A" })

Output JSON:

json
[ { "userId": 1, "userName": "Alice", "userEmail": "N/A" }, { "userId": 2, "userName": "Bob", "userEmail": "bob@example.com" } ]

In this example, the default keyword is used to set default values for the userEmail property if it is null in any of the objects in the input array.

**1. Grouping and Aggregation:

Scenario:

You have a list of orders, and you want to group them by customer ID and calculate the total order amount for each customer.

Input JSON:

json
[ { "customerId": 1, "orderAmount": 100 }, { "customerId": 2, "orderAmount": 150 }, { "customerId": 1, "orderAmount": 200 }, { "customerId": 3, "orderAmount": 120 } ]

DataWeave Transformation:

dw
%dw 2.0 output application/json --- payload groupBy $.customerId mapObject ((value, key, index) -> { customerId: key, totalOrderAmount: value sum ((order) -> order.orderAmount) })

Output JSON:

json
{ "1": { "customerId": 1, "totalOrderAmount": 300 }, "2": { "customerId": 2, "totalOrderAmount": 150 }, "3": { "customerId": 3, "totalOrderAmount": 120 } }

In this example, the groupBy function is used to group orders by customerId, and then the sum function is used to calculate the total order amount for each customer.

2. Streaming Data Processing:

DataWeave supports streaming, allowing you to process large datasets efficiently without loading the entire dataset into memory.

Scenario:

You have a large CSV file, and you want to process it line by line without loading the entire file into memory.

DataWeave Transformation:

dw
%dw 2.0 input payload application/csv separator="," output application/json --- payload map ((row) -> { id: row.id, name: row.name })

In this example, the input directive specifies that the input payload is a CSV file, and the transformation is performed row by row without loading the entire CSV file into memory.

3. Error Handling:

Scenario:

You want to handle errors gracefully during data transformation and provide custom error messages.

DataWeave Transformation:

dw
%dw 2.0 output application/json --- try { // Data transformation logic } catch (error) { { error: error.message } }

In this example, the try block contains the data transformation logic. If an error occurs, the catch block captures the error message and provides a custom error response in the output.

4. External Data Sources:

DataWeave allows you to interact with external data sources, such as databases or APIs, to fetch and transform data in real-time.

Scenario:

You want to fetch data from an external API and transform it.

DataWeave Transformation:

dw
%dw 2.0 output application/json --- using (http::get("https://api.example.com/data")) payload map ((item) -> { id: item.id, name: item.name })

In this example, the http::get function is used to fetch data from an external API, and then the data is transformed using DataWeave.


Module 4: DataWeave Best Practices

When working with DataWeave in MuleSoft applications, following best practices ensures that your transformations are efficient, maintainable, and performant. Here are some DataWeave best practices to consider:

1. Code Readability and Maintainability:

  • Use Descriptive Variable Names: Use meaningful variable names that describe the data they hold. Clear variable names enhance readability.

    dw
    var orderDetails = payload.order
  • Add Comments: Add comments to explain complex logic, especially if the transformation involves intricate business rules or calculations.

    dw
    /* * Calculate total price by summing up item prices */ var totalPrice = payload.items map ((item) -> item.price) sumBy ((price) -> price)

2. Error Handling:

  • Handle Errors Gracefully: Implement error handling mechanisms, such as try-catch blocks, to gracefully handle errors and provide meaningful error messages in the output.

    dw
    try { // Transformation logic } catch (error) { { error: error.message } }

3. Performance Optimization:

  • Minimize Nested Transformations: Avoid deep nesting of transformations. Deeply nested transformations can impact performance. Consider breaking down complex transformations into smaller, manageable steps.

  • Use Streaming: Whenever possible, use streaming to process large datasets efficiently. Streaming allows processing data item by item, reducing memory usage.

    dw
    %dw 2.0 input payload application/csv header=true output application/json stream=false --- payload map ((row) -> { id: row.id, name: row.name })

4. Data Validation:

  • Validate Input Data: Validate input data to ensure it meets the expected format and structure. Implement checks to handle unexpected or malformed data gracefully.

5. Reusability:

  • Use Functions: Encapsulate reusable logic in functions. Functions promote code reuse and readability.

    dw
    %dw 2.0 fun calculateTax(amount: Number): Number = amount * 0.1 --- { total: payload.amount, tax: calculateTax(payload.amount) }

6. Version Control:

  • Use Version Control: Store your DataWeave scripts in version control systems (e.g., Git). Version control helps track changes, collaborate with team members, and maintain a history of transformations.

7. Testing:

  • Unit Testing: Write unit tests for your DataWeave transformations. Unit tests validate that transformations produce the expected output for given input data and logic.

8. Documentation:

  • Document Your Transformations: Document complex transformations, especially if they involve business rules or unique logic. Clear documentation aids developers who work with the code later.

Comments

Popular posts from this blog

Mulesoft Dataweave Practice Questions-2025

1. map (Transform elements in an array or object) Map an array of numbers to their squares: Input: [1, 2, 3, 4] Output: [1, 4, 9, 16] Dataweave %dw 2.0 output application/json --- payload map ($*$) Convert an array of strings to uppercase: Input: ["apple", "banana", "cherry"] Output: ["APPLE", "BANANA", "CHERRY"] Prefix all keys in an object with "key_": Input: {"name": "John", "age": 25} Output: {"key_name": "John", "key_age": 25} Map an array of objects to only include specific fields: Input: [ {"name": "John", "age": 25, "city": "New York"}, {"name": "Jane", "age": 30, "city": "Los Angeles"} ] Output: [{"name": "John", "city": "New York"}, {"name": "Jane", "city": "Los Angeles...

Dataweave My Practice

 https://www.caeliusconsulting.com/blogs/transforming-messages-with-dataweave/ Add 1 to each value in the array  [1,2,3,4,5]              Ans: %dw 2.0 output application/json --- payload map $+ 1  2) Get a list of  id s from:                [ { "id": 1, "name": "Archer" }, { "id": 2, "name": "Cyril" }, { "id": 3, "name": "Pam" } ] %dw 2.0 output application/json --- payload map $.id   ___________________________________________________________________________________ Example 1 : Using the input data, we'll produce a patterned output based on the given array. Input: [ { "name" : "Roger" }, { "name" : "Michael" }, { "name" : "Harris" } ] Output: [ { "user 1" : "Roger" }, { "user 2" : "Micheal" }, { "user 3" : "Harris...

Mule Interview Questions

### **1. Core MuleSoft Concepts** #### **What is MuleSoft, and what are its key components?** - **MuleSoft** is an integration platform that enables organizations to connect applications, data, and devices seamlessly. - **Key Components**:   - **Anypoint Platform**: The core platform for designing, building, and managing APIs and integrations.   - **Anypoint Studio**: The IDE for developing Mule applications.   - **Anypoint Exchange**: A repository for sharing APIs, templates, and connectors.   - **Runtime Engine**: Executes Mule applications.   - **API Manager**: Manages and secures APIs.   - **DataWeave**: Transformation language for data mapping. #### **Explain the API-led connectivity approach in MuleSoft.** - **API-led connectivity** is a method of connecting data and applications through reusable APIs. - It consists of three layers:   1. **System APIs**: Expose data from core systems.   2. **Process APIs**: Orchestrate data and business logi...