Skip to content

Instantly share code, notes, and snippets.

@mokamoto
Created September 21, 2018 03:49
Show Gist options
  • Save mokamoto/076f7d4ddba1e45a2adff6e7439aa3e0 to your computer and use it in GitHub Desktop.
Save mokamoto/076f7d4ddba1e45a2adff6e7439aa3e0 to your computer and use it in GitHub Desktop.
MuleSoftハンズオン - Dataweaveスクリプト
%dw 2.0 // The version
output application/json // The mime-type of the output
var product = payload[0] // Setting a variable called product with a value of the first item of query's payload
---
{
identifier: product.uuid,
identifiers: read(product.identifiers default "[]","application/json"), // Parsing this string to a JSON object. If null, defaults to empty array to avoid a null exception.
price: {
amount: {
currencyValue: product.currencyValue,
name: product.currencyName default "Amount", // Setting a default value if value is null
currency: product.currency
},
salesUnit: {
code: product.salesUnitCode,
name: product.salesUnitName
}
},
description: product.description,
model: product.model,
brand: product.brand,
pictures: read(product.pictures default "[]","application/json") // Parsing this string to a JSON object. If null, defaults to empty array to avoid a null exception.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment