bloblang

Executes a Bloblang mapping on messages.

# Config fields, showing default values
bloblang: ""

Bloblang is a powerful language that enables a wide range of mapping, transformation and filtering tasks. For more information check out the docs.

Error Handling

Bloblang mappings can fail, in which case the message remains unchanged, errors are logged, and the message is flagged as having failed, allowing you to use standard processor error handling patterns.

However, Bloblang itself also provides powerful ways of ensuring your mappings do not fail by specifying desired fallback behaviour, which you can read about in this section.

Examples

Mapping

Given JSON documents containing an array of fans:

{
"id":"foo",
"description":"a show about foo",
"fans":[
{"name":"bev","obsession":0.57},
{"name":"grace","obsession":0.21},
{"name":"ali","obsession":0.89},
{"name":"vic","obsession":0.43}
]
}

We can reduce the fans to only those with an obsession score above 0.5 with this mapping:

pipeline:
processors:
- bloblang: |
root = this
fans = fans.map_each(match {
this.obsession > 0.5 => this
_ => deleted()
})

Giving us:

{
"id":"foo",
"description":"a show about foo",
"fans":[
{"name":"bev","obsession":0.57},
{"name":"ali","obsession":0.89}
]
}

Parsing CSV

Bloblang can be used to parse some basic CSV files, given files of the following format:

foo,bar,baz
1,2,3
7,11,23
89,23,2

We can write a parser that does cool things like calculating the sum of each line:

pipeline:
processors:
- bloblang: |
root = content().string().split("\n").enumerated().map_each(match {
index == 0 => deleted() # Drop the first line
_ => match value.trim() {
this.length() == 0 => deleted() # Drop empty lines
_ => this.split(",") # Split the remaining by comma
}
}).map_each(
# Then do something cool like sum each row
this.map_each(this.trim().number(0)).sum()
)

To give an output like this:

[6,41,114]