Language Reference
Introduction
Introduction to the lam data transformation language.
Lam Language
Lam
is a DSL for data transformation.
It runs on the Laminar platform and is used to transform data when flows
are executed.
Our language documentation is currently under construction. Please check back soon for a full language reference.
Example
In this example, we will transform the following JSON:
{
"message": "Hello lam",
"foo": "delete me",
"http_status": "200"
}
Into the following JSON:
{
"message": "Hello lam",
"timestamp": "2021-01-01T00:00:00Z",
"http_status_code": 200,
"status": "success"
}
Using the following lam
script:
# Remove some fields
del(.foo)
# Add a timestamp
.timestamp = now()
# Parse HTTP status code into local variable
http_status_code = parse_int!(.http_status)
del(.http_status)
# Add status
if http_status_code >= 200 && http_status_code <= 299 {
.status = "success"
} else {
.status = "error"
}
Here’s what’s happening:
del(.foo)
removes thefoo
field from the input..timestamp = now()
adds a new field calledtimestamp
with the current time.http_status_code = parse_int!(.http_status)
parses thehttp_status
field into a local variable calledhttp_status_code
.del(.http_status)
removes thehttp_status
field from the input.if http_status_code >= 200 && http_status_code <= 299 {
starts an if statement..status = "success"
adds a new field calledstatus
with the valuesuccess
.} else {
starts the else block..status = "error"
adds a new field calledstatus
with the valueerror
.}
ends the if statement.
With the input our script will produce the following output:
{
"message": "Hello lam",
"timestamp": "2021-01-01T00:00:00Z",
"http_status_code": 200,
"status": "success"
}
We can easily modify the script to produce different output. For example, we can change the status
field to be a boolean called succeeded
:
# Remove some fields
del(.foo)
# Add a timestamp
.timestamp = now()
# Parse HTTP status code into local variable
http_status_code = parse_int!(.http_status)
del(.http_status)
# Add succeeded
if http_status_code >= 200 && http_status_code <= 299 {
.succeeded = true
} else {
.succeeded = false
}
This will produce the following output:
{
"message": "Hello lam",
"timestamp": "2021-01-01T00:00:00Z",
"http_status_code": 200,
"status": true
}
Want to learn more?
Was this page helpful?