Preprocessing Field Options

Allows content to be processed before any additional formatting is applied. Once processed other options such as cleansing, prefix, suffix are applied. Only fields with content are processed. This option should only be used on fields that do not update back to a data source, because there is no way of reversing the process.  Ensure that preprocessing is stand-alone and not reliant on the formatted content of other fields as they may not exist at the point the script is called.

The following methods are built into EasyCatalog:

Lua

The content is passed as a ‘content’ variable and the return value is used as the new content. For example:

Parsing JSON into text using jsoncursor:

 

Mustache

Mustache is a logicless template engine for creating dynamic content from JSON fields.

A typical Mustache template:

Given the following field content:

Will produce the following:

Here’s another example, which uses a template to create a HTML table which can then be loaded as Tabular Field. Original JSON data:

And the template:

JMESPath

JMESPath (JSON Matching Expression Paths) is a query language for search JSON. It allows you to declaratively extract elements from JSON. For example:

Given the following field content:

Will produce the following:

XPath

XPath can be used to navigate through elements and attributes of an XML field. Given the following field content:

The XPath:

Would give the result:

JSONPath

JSONPath is a query language for JSON, similar to XPath for XML. It allows you to select and extract data from a JSON document.
JSONPath expressions begin with the dollar sign ($) character, which refers to the root element. The dollar sign is followed by a sequence of child elements, which are separated via dot (code) notation or via the square brackets (code).

The important JSONPath syntax rules are:

  • $ symbol refers to the root object or element.
  • @ symbol refers to the current object or element.
  • . operator is the dot-child operator, which you use to denote a child element of the current element.
  • [ ] is the subscript operator, which you use to denote a child element of the current element (by name or index).
  • * operator is a wildcard, returning all objects or elements regardless of their names.
  • , operator is the union operator, which returns the union of the children or indexes indicated.
  • : operator is the array slice operator, so you can slice collections using the syntax [start:end:step] to return a subcollection of a collection.
  • ( ) operator lets you pass a script expression in the underlying implementation’s script language. It’s not supported by every implementation of JSONPath, however.
  • ? ( ) to query all items that meet a certain criteria.
  • Take this example JSON:
Then to get Bobs age, the JSONPath would be

$.people[?(@.name == ‘Bob’)].age