Whistle basics
This page describes the basics of writing a mapping in Whistle to transform data from one schema to another.
For a list of built-in Whistle functions, see the Whistle built-in function reference, and for a list of MDE-specific functions, see the Whistle MDE function reference.
Simple mapping
The following section outlines some array outputs.
Add array outputs
If you use the following Whistle code sample:
Planet[0]: "Earth";
Planet[1]: "Mars";
Planet[2]: "Jupiter";
Moon[0]: "Luna";
The output would be the following:
{
"Moon": [
"Luna"
],
"Planet": [
"Earth",
"Mars",
"Jupiter"
]
}
To add another moon, Io, before Luna, edit your Whistle code as follows:
Planet[0]: "Earth";
Planet[1]: "Mars";
Planet[2]: "Jupiter";
Moon[0]: "Io";
Moon[1]: "Luna";
With the previous input, the output will be the following:
{
"Moon": [
"Io",
"Luna"
],
"Planet": [
"Earth",
"Mars",
"Jupiter"
]
}
Define and call functions
This section describes call functions.
Defining functions
A function in Whistle is a set of mappings that produce a JSON object. The function maps a set of inputs to a set of fields in the resulting JSON object. The following examples use a function to add structure to the planets from the previous section.
Planet[0]: PlanetName_PlanetInfo("Earth");
Planet[1]: PlanetName_PlanetInfo("Mars");
Planet[2]: PlanetName_PlanetInfo("Jupiter");
Moon[0]: MoonName_MoonInfo("Luna");
def PlanetName_PlanetInfo(planetName) {
name: planetName;
type: "Planet"
}
def MoonName_MoonInfo(moonName) {
name: moonName;
type: "Moon"
}
With the previous input, the output would be the following:
{
"Moon":