Bloblang, or blobl for short (pronounced "blobble"), is a language designed specifically for mapping unstructured data. It's a safe, fast, and powerful way to perform document mapping within Benthos.
You can also execute bloblang mappings on the command line with the
An assignment consists of a left-hand-side assignment target and a right-hand-side mapping query.
Map a new document by using dot paths:
The newly mapped document starts off empty, if you wish to begin your mapping with a full copy of the input object then start your map by assigning it to the root:
Variables help with value reuse:
You can also use Bloblang to set and reference metadata values:
The pipe operator (
|) used within brackets allows you to coalesce values within a path:
Literals and Arithmetic
Bloblang supports number, boolean, string, null, array and object literals:
You might've already spotted, comments are started with a hash (
#) and end with a line break:
Boolean Logic and Arithmetic
Bloblang supports a range of boolean operators
|| and arithmetic operators
if expressions to perform maps conditionally:
And add an
else for alternative maps:
match expression allows you to perform conditional mappings on a value using boolean logic:
Match cases can specify a literal value for simple comparison:
The match context can also be left unset, and the catch-all case can also be omitted:
If no case matches then the mapping is skipped entirely, hence we would end up with the original document in this case.
Functions can be placed anywhere and allow you to extract information from your environment, generate values, or access data from the underlying message being mapped:
You can find a full list of functions in this doc.
Methods provide most of the power in Bloblang as they allow you to augment values by chaining them:
You can find a full list of methods in this doc.
It's possible to declare reusable maps for common operations:
And even import maps from other files:
By assigning the root of a mapped document to the
deleted() function you can delete a message entirely:
Functions and methods can fail under certain circumstances, such as when they receive types they aren't able to act upon. These failures, when not caught, will cause the entire mapping to fail. However, the method
catch can be used in order to return a value when a failure occurs instead:
catch is a method it can also be attached to bracketed map expressions:
catch method only acts on errors, sometimes it's also useful to set a fall back value when a query returns
null in which case the method
or can be used the same way: