Custom computation
Define your own computed field method using JsonLogic. For example, return the sum of two fields, map arrays, or return a boolean indicating if a field’s output is non-null.
Parameters
The following parameters are in the computed field’s global Method parameter:
key | value | description |
---|---|---|
id (required) | customComputation | - This method has access to the parsed_document object at verbosity = 0. - This method doesn’t infer Sensible types. It outputs string, number, boolean, null , or an array of those. For example, adding two currencies results in a number. - This method returns null if you attempt to reference a variable that Sensible can’t find in the parsed_document. - This method returns null if calculations include a null. For example, 5 + null field = null. If you instead want 5 + null field = 5, then implement logic to replace nulls with zeros. For an example, see Example 1. |
jsonLogic (required) | JsonLogic object | Transforms the output of one or more Field objects using JsonLogic. Supports all JsonLogic operations and extends them with Sensible operations. For more information, see the following section. Double escape any dots in the field keys (for example, delivery\\.zip\\.code). Use dot notation to access arrays, for example, test_table.columns.3.values to access the 4th column in a table. |
Sensible operations
Sensible extends JsonLogic with the following operations:
Exists
Most commonly used with the JsonLogic var
operation to test that an output value isn’t null. The var
operation retrieves extracted field values using field id
keys.
Match
Where regex
is a Javascript-flavored regular expression.
Double escape special regex characters, since the regex is in a JSON object (for example, \\s
, not \s
, to represent a whitespace character). This operation does not support regular expression flags such as i
for case insensitive.
Replace
One of the following syntaxes:
Or:
Where regex
is a Javascript-flavored regular expression. Double escape special regex characters, since the regex is in a JSON object (for example, \\s
, not \s
, to represent a whitespace character). This operation supports:
- regex capturing groups
- regex flags, such as
i
for case insensitive.
Examples
Example 1
The following example shows defining custom computed fields.
Config
Example document
The following image shows the example document used with this example config:
Example document | Download link |
---|
Output
Example 2
The following example shows using the Custom Computation method to perform the following operations on data extracted from an claims loss run insurance document:
- Get the total number of claims listed in the document
- Redact the claim IDs
- Sum up the incurred cost for all claims listed
Config
Example document
The following image shows the example document used with this example config:
Example document | Download link |
---|
Output