Design
Overview
Translate raw data into human readable text.
COMMUNITY FEATURE
Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
v2.0+
Formatters can be used to translate raw data into human readable text.
A formatter is applied to data using the separator :
. Multiple formatters can be used one after another, each formatter input is the output of the previous one. Some formatters accept constant or dynamic parameters.
Here is an example showing how to write "John"
instead of "JOHN"
using two chained formatters, and how to translate a raw ISO date into a human readable date.
Constant parameters
Many formatters accept one or multiple parameters, separated by commas, enclosed in parentheses to modify the output.
For example, the formatter :prepend(myPrefix)
adds the prefix "myPrefix."
If your constant parameter contains a comma or whitespace, you must wrap the text with single quotes (straight quotes): prepend('my prefix')
.
Configure your text editor to prevent quote replacement.
Dynamic parameters
Formatters accept dynamic variables if parameters start with a .
and is not surounded by quotes.
Carbone accepts two methods:
- with an absolute JSON path, starting with
d.
(root of the data object) orc.
(root of the complement object) with some limitations - with a relative JSON path from the parent object, starting with a dot
.
Here is the dataset used for the following examples:
{
"id" : 10,
"qtyA" : 20,
"subObject" : {
"qtyB" : 5,
"qtyC" : 3
},
"subArray" : [{
"id" : 1000,
"qtyE" : 3
}]
}
Do a mathematical operation of d.subObject.qtyB
+ d.subObject.qtyC
:
{d.subObject.qtyB:add(d.subObject.qtyC)} // 8 (5 + 3)
Shorter alternative, with a relative JSON path:
{d.subObject.qtyB:add(.qtyC)} // 8 (5 + 3)
Multiple dots can be used to access parent attributes with a relative JSON path:
{d.subObject.qtyB:add(..qtyA):add(.qtyC)} // 28 (5 + 20 + 3)
Here is the same computation using absolute JSON path:
{d.subObject.qtyB:add(d.qtyA):add(d.subObject.qtyC)} // 28 (5 + 20 + 3)
Read parent objects and their children attributes (there is no limit in depth):
{d.subArray[0].qtyE:add(..subObject.qtyC)} // 6 (3 + 3)
Access the first item of another table (only positive integers):
{d.subObject.qtyB:add(..subArray[0].qtyE)} // 8 (5 + 3)
Known limitations:
Using custom iterators or array filters is forbidden:
{d.subObject.qtyB:add(..subArray[i].qtyE)}
{d.subObject.qtyB:add(..subArray[index, something=3].qtyE)}
{d.subObject.qtyB:add(d.subArray[i].qtyE)}
{d.subObject.qtyB:add(d.subArray[index].qtyE)}