Expressions and functions

Last Updated: Jan 10, 2017 11:30AM CET

In this article

    Here's a list of expressions that can be applied to the feed value in order to manipulate the output value to your liking. All expressions can be combined and is executed inwards out as seen visually.

     

    Numeric expressions

    Expression Pre-expression result Post-expression result
    abs($.feed.path, "-9.5") -9.5 9.5
    ceiling($.feed.path) 0.2 1
    floor($.feed.path") 0.7 0
    round($.feed.path) 0.5 1
    round($.feed.path, "2") 0.5 0.50
    add($.feed.path, "10") 100 110
    sub($.feed.path, "10") 100 90
    mul($.feed.path, "10") 100 1000
    div($.feed.path, "10") 100 10
    mod($.feed.path, "10") 111 1
     

    Text/string expressions

    Expression Pre-expression result Post-expression result
    StringJoin($.feed.path, " ") Hello,World Hello World
    StringLength($.feed.path," ", "0") Hello World 9
    SubString($.feed.path,"6")

    Hello World

    World
    SubString($.feed.path,"3","5")

    Hello World

    lo Wo
    split($.feed.path," ", "1") Hello World World
    NormalizeSpace($.feed.path) Hello  World Hello World
    UpperCase($.feed.path) hello world HELLO WORLD
    LowerCase($.feed.path) Hello World hello world
    proper($.feed.path) hello world Hello world
    capitalize($.feed.path, " ", "0") hello world Hello World
    replace($.feed.path, "Hi", "Hello") Hi World Hello World
    trim($.feed.path)  Hello World  Hello World
    trim($.feed.path, "5") Hello World Hello
    trim($.feed.path, "6", "...") Hello World Hello...
     

    List manipulation

    Expression Pre-expression result Post-expression result
    remove($.feed.path, "1") a,b,c,d b,c,d
    distinct($.feed.path) a,b,b,c a,b,c
    reverse($.feed.path) a,b,c c,b,a
    SubSequence($.feed.path, "2") a,b,c,d c,d
    SubSequence($.feed.path, "1", "2") a,b,c,d b,c
    count($.feed.path) a,b,c,d 4
    sum($.feed.path) 1,2,3 6
    avg($.feed.path) 1,2,3 2
    min($.feed.path) 1,2,3 1
    max($.feed.path) 1,2,3 3
     

    Formatting

    Expression Pre-expression result Post-expression result
    format($.feed.path, "en-gb") 10 10.00
    format($.feed.path, "en-gb", "currency") 10 £10.00
    format($.feed.path, "en-gb", "currency", "0") 10 £10
    format($.feed.path, "en-gb", "number", "0") £10 10
    currencyconvert($.feed.path, "USD", "SEK") 10 87.06...
    dateformat($.feed.path, "dd/MM/yyyy") 2015-04-23 23/04/2015
    dateformat($.feed.path, "dd MMMM, yyyy","en-gb") 2015-04-23 23 April 2015
    dateconvert($.feed.path,"0", "2","dd MMMM, yyyy","en-gb") 2015-04-23 15:00 23 April 2015 17:00
     
    Note that dateconvert takes 4 arguments; UTC-from (numeral), UTC-to (numeral), Format, Language.
     

    Misc

    Custom

    Expression Pre-expression result Post-expression result
    "Hello World"   Hello World
    Custom("Hello World")   Hello World
    Custom("Hello","World","BannerFlow")   Hello, World, BannerFlow
     

    Combining

    Any expression and/or value can be combined, this is useful if you want to type out complete messages that includes values from the feed.
    Expression Pre-expression result Post-expression result
    "Book your trip to " + $.feed.path + "!"   Book your trip to Stockholm!
    $.feed.path.book + " by " + $.feed.path.author    On Immunity by Eula Biss
     

    Advanced JSONPath

    JSONPath is the structural language that allows to find and select the data a specific field should represent.

    Please note

    XML feeds are still eligible for usage in BannerFlow despite JSONPath being utilized. The paths will work out of the box nonetheless.

    JSONPath expressions

    JSONPath Sample Description
    $ $ The root object/element
    @   The current object/element (exclusively used in Selection filters)
    .   Child operator
    .. $.feed.path..category.@value Recursive descent
    * $.feed.path.* Wildcard. All objects/elements regardless of their names.
    @ $.feed.path.@value Attribute access. Only works for XML as JSON don't have attributes
    [] $.feed.path[0] Selection filter. See further down how this is used
    [start:end:step] $.feed.path[-1:] Slicing the result array
    ?() $.feed.path[?()] Applies a filter (script) expression. (used within the Selection filter)
    #text  $.feed.path.#text The text/node value of the selected node (only applicable for XML feeds).
     

    Selection filters

    Note that any value comparisons has to be encased with apostrophes (')
    Selection Result
    $.feed.path[0] Selects the first value in path
    $.feed.path[?(@.price > 10)].value Select all path values where price is higher than 10
    $.feed.path[?(@.@type == '1')].value Selects all path values where the attribute type equals 1 (Use .type for json feeds)
    $.feed.path[?(@.price > 10 && @.price < 20)].value Select all path values where type is 1 and price is higher than 10
    $.feed.path[?(@.price < 30 || @.priceType == 'onsale')].value Select all path values where price is less than 30 or if priceType equals onsale
    support@bannerflow.com
    https://cdn.desk.com/
    false
    desk
    Loading
    seconds ago
    a minute ago
    minutes ago
    an hour ago
    hours ago
    a day ago
    days ago
    about
    false
    Invalid characters found
    /customer/en/portal/articles/autocomplete