Transformation

<script type="edgeside/transformation" ...>

A Transformation element is both a consumer and a producer of context data. It takes an input and applies a transformation to it to produce an output.

Attributes

Name Description Required?
data-edgeside-input specifies a key under which the transform element can expect to find the data it needs to transform. yes
data-edgeside-output specifies a key under which the template processor will output transformed data yes

Element content

A transformation written in the JSONata transformation language.


Examples

example1 - Format Timezone Data

We fetch some data from a service, but unfortunately the data is not exactly in the format we need. We use the transform element to apply a JSONata transofrmation to it. In this case we define a couple of helper functions ($offset and $formattedDateTime) and then use these in our declaration of the output that we want. In this example we then simply output our transformed data directly using the Debug element.

<script type="edgeside/rest"
data-edgeside-output="londonTime"
data-edgeside-endpoint="http://worldtimeapi.org/api/timezone/Europe/London" >

</script>

<script type="edgeside/transform"
data-edgeside-input="londonTime"
data-edgeside-output="londonTimeFormatted" >

(
$offset:=$substringBefore(utc_offset,":")&$substringAfter(utc_offset,":");
$formattedDateTime:=function($fmt){$fromMillis($toMillis(datetime),$fmt, $offset)};

{
"timezone":timezone,
"day_of_year":day_of_year,
"datetime": $formattedDateTime('[M01]/[D01]/[Y0001] [h#1]:[m01][P]'),
"beeroclock":$number($formattedDateTime('[H#1]'))>=17
}
)
</script>

<script type="edgeside/debug" data-edgeside-input="londonTimeFormatted" >
</script>

Live Results:

Live Results (Source):