Skip to main content

Creating a New DataWeave Transformation from Inputs and Outputs

This guide explains how to generate DataWeave code using input and output examples. This is useful when you want to create a new DataWeave transformation without starting from scratch. There are a few ways to achieve this:

1. Using the DataWeave Generator with Input and Output Examples

This method allows you to generate DataWeave transformation code by providing example input and output data. The DataWeave Generator, powered by Curie, analyzes these examples and produces transformation code that maps the input data structure to the desired output format.

Estimated Time: Few seconds to few minutes (depending on the complexity of the transformation).

Steps:

  1. Provide Sample Input Data: Supply the data in its original format (e.g., XML, JSON, CSV, EDI). The more representative the data, the better the generated DataWeave code will be.
  2. Provide Sample Output Data: Define the desired data format and structure of the output.
  3. Optional: Flexible Configuration for Improved Accuracy:
    • Provide multiple input and output examples: Supplying a variety of examples helps Curie better understand the desired mappings and account for variations in data.
    • Add extra transformation notes: Specific details or constraints about the transformation guide Curie in generating more precise code.
  4. Let Curie Generate the Code: Based on your inputs, Curie will generate DataWeave transformation code.

Example Transformation

Transforming XML input into JSON output.

Sample Input Data (XML)

<?xml version='1.0' encoding='UTF-8'?>
<order>
<product>
<price>5</price>
<model>MuleSoft Connect 2016</model>
</product>
<item_amount>3</item_amount>
<payment>
<payment-type>credit-card</payment-type>
<currency>USD</currency>
<installments>1</installments>
</payment>
<buyer>
<email>mike@hotmail.com</email>
<name>Michael</name>
<address>Koala Boulevard 314</address>
<city>San Diego</city>
<state>CA</state>
<postCode>1345</postCode>
<nationality>USA</nationality>
</buyer>
<shop>main branch</shop>
<salesperson>Mathew Chow</salesperson>
</order>

Sample Output Data (JSON)

{
"address1": "Koala Boulevard 314",
"city": "San Diego",
"country": "USA",
"email": "mike@hotmail.com",
"name": "Michael",
"postalCode": "1345",
"stateOrProvince": "CA"
}

2. Using the DataWeave Generator with a Mapping Table

Alternatively, you can use a mapping table (e.g., in XLSX format) to define the data transformations. Curie will then generate DataWeave code based on this table.

Estimated Time: ~2 mins

Steps:

  1. Create a Mapping Table: Define the mappings between the input and output fields in an XLSX file.
  2. Upload the Mapping Table: Upload the XLSX file to the DataWeave Generator.
  3. Optional: Add Notes: Include additional instructions or context to guide Curie in generating the code.
  4. Let Curie Generate the Code: Based on the mapping table, Curie will generate DataWeave transformation code.

Flexible Options for Custom Transformations

  • Add Notes: Include details like sample input/output data and/or any specific instructions to guide Curie in generating accurate transformations.
  • Supported Data Types: The generator currently supports transformations across these data types: json, ndjson, xml, csv, text, and yaml.

3. Generating JSON/XML from EDI

Curie can also generate DataWeave code to transform EDI documents into JSON or XML formats. This is achieved by providing sample EDI input and corresponding JSON/XML output examples.

Sample EDI Input

ISA*00*          *00*          *ZZ*NTORETAIL      *01*MYTHICAL       *200915*0103*U*00401*000000018*0*P*>~
GS*PO*NTORETAIL *MYTHICAL *20200915*0103*18*X*004010~
ST*850*0001~
BEG*00*NE*PO-DEMO-20200912-002**20191018~
REF*VR*7429271~
PER*BD*Tim Brown*EM*tbrown@nto.com~
PO1*1*20**34.45****MG*324791~
PID*F****8.5″ x 11″ Copy Paper, 20 lbs, 92 Brightness, 5000/Carton (324791)~
N1*ST*Salesforce West*92*338~
N3*50 Fremont St*Suite 1456~
N4*San Francisco*CA*94105*US~
PO1*2*80**1.95****MG*2072174~
PID*F****Hype Tank Highlighters, Chisel, Yellow, Dozen (29203)~
N1*ST*Salesforce East*92*367~
N3*350 Mission St*Floor 5~
N4*San Francisco*CA*94105*US~
PO1*3*65**5.08****MG*163865~
PID*F****Notepads, 8.5″ x 11.75″, Wide Ruled, White, 50 Sheets/Pad, 12 Pads/Pack (51295/2~
N1*ST*Salesforce Tower*92*587~
N3*415 Mission St*Floor 3~
N4*San Francisco*CA*94105*US~
PO1*4*30*PH*11.77****MG*467951~
PID*F****Lightweight Moving & Storage Packing Tape, 1.88″W x 54.6 Yards, Clear, 6 Rolls (~N1*ST*Tableau Palo Alto*92*1564~
N3*260 California Ave*Ste 300~
N4*Palo Alto*CA*94306*US~
CTT*4~
SE*26*0001~
GE*1*18~
IEA*1*000000018~

Sample JSON Output

[
{
"PurchaseOrder": {
"POPurpose": "New",
"POType": "NE",
"PONumber": "PO-DEMO-20200912-002",
"CustomerId": "A43836686",
"CustomerName": "Ohana Incorporated",
"BuyerName": "Tim Brown",
"BuyerEmailID": "tbrown@nto.com",
"PODate": "2019-10-18T00:00:00-07:00",
"POLineItems": [
{
"PurchaseOrderLineId": "PO-DEMO-20200912-002-0",
"LineNum": "1",
"Quantity": "20",
"UnitPrice": "34.45",
"ItemDescription": "8.5″ x 11″ Copy Paper, 20 lbs, 92 Brightness, 5000/Carton (324791)",
"SupplierItemNum": "324791",
"POLineLocation": {
"LineLocationId": "338",
"ShipToLocation": {
"ShipToLocationCode": "338",
"ShipToLocationName": "Salesforce West",
"Address": {
"AddressLine1": "50 Fremont St",
"AddressLine2": "Suite 1456",
"City": "San Francisco",
"PostalCode": "94105",
"State": "CA",
"Country": "US"
}
}
}
},
{
"PurchaseOrderLineId": "PO-DEMO-20200912-002-1",
"LineNum": "2",
"Quantity": "80",
"UnitPrice": "1.95",
"ItemDescription": "Hype Tank Highlighters, Chisel, Yellow, Dozen (29203)",
"SupplierItemNum": "2072174",
"POLineLocation": {
"LineLocationId": "367",
"ShipToLocation": {
"ShipToLocationCode": "367",
"ShipToLocationName": "Salesforce East",
"Address": {
"AddressLine1": "350 Mission St",
"AddressLine2": "Floor 5",
"City": "San Francisco",
"PostalCode": "94105",
"State": "CA",
"Country": "US"
}
}
}
},
{
"PurchaseOrderLineId": "PO-DEMO-20200912-002-2",
"LineNum": "3",
"Quantity": "65",
"UnitPrice": "5.08",
"ItemDescription": "Notepads, 8.5″ x 11.75″, Wide Ruled, White, 50 Sheets/Pad, 12 Pads/Pack (51295/2",
"SupplierItemNum": "163865",
"POLineLocation": {
"LineLocationId": "587",
"ShipToLocation": {
"ShipToLocationCode": "587",
"ShipToLocationName": "Salesforce Tower",
"Address": {
"AddressLine1": "415 Mission St",
"AddressLine2": "Floor 3",
"City": "San Francisco",
"PostalCode": "94105",
"State": "CA",
"Country": "US"
}
}
}
},
{
"PurchaseOrderLineId": "PO-DEMO-20200912-002-3",
"LineNum": "4",
"Quantity": "30",
"UnitPrice": "11.77",
"ItemDescription": "Lightweight Moving & Storage Packing Tape, 1.88″W x 54.6 Yards, Clear, 6 Rolls (",
"SupplierItemNum": "467951",
"POLineLocation": {
"LineLocationId": "1564",
"ShipToLocation": {
"ShipToLocationCode": "1564",
"ShipToLocationName": "Tableau Palo Alto",
"Address": {
"AddressLine1": "260 California Ave",
"AddressLine2": "Ste 300",
"City": "Palo Alto",
"PostalCode": "94306",
"State": "CA",
"Country": "US"
}
}
}
}
]
}
}
]