Bannernow supports both XML and JSON dynamic feeds

XML feeds are automatically converted to JSON format within Bannernow. You can use the default JSON path to extract data from your feed easily.

JSONPath is a special language for extracting data from XML or JSON feeds.

JSONPath uses special notation to represent nodes and their connections to adjacent nodes in a JsonPath path. There are two styles of notation, namely dot and bracket.

Both of the following paths refer to the same node from the above JSON document, which is the third element within the books field of store node under the root node.

With dot notation

$.store.books[2]

With bracket notation:

$[‘store‘][‘books‘][2]

Operators:

We have several helpful operators in JsonPath:

Root node ($): This symbol denotes the root member of a JSON structure no matter it is an object or array. Its usage examples were included in the previous sub-section.

Current node (@): Represents the node that is being processed, mostly used as part of input expressions for predicates. Suppose we are dealing with book array in the above JSON document, the expression book[?(@.price == 49.99)] refers to the first book in that array.

Wildcard (*): Expresses all elements within the specified scope. For instance, book[*] indicates all nodes inside a book array.

Let’s practice JSONPath expressions by some more examples. We start with a simple JSON structure:

{ "store": {
    "date": "Feb 9 2017",
    "book": [
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8
      },
      { "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honor",
        "price": 12
      },
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 12
      }
    ],
    "bicycle": {
      "title": " Cool Bicycle ",
      "color": "Red",
      "price": "19.95",
      "oprice": 19.5,
      "rating": -10
    }
  }
}

 

JSONPathResult
$.store.book[*].authorthe authors of all books in the store
$..authorall authors
$.store.*all things in store, which are some books and a red bicycle.
$.store..pricethe price of everything in the store.
$..book[2]the third book
$..book[(@.length-1)]
$..book[-1:]
the last book in order.
$..book[0,1]
$..book[:2]
the first two books
$..book[?(@.isbn)]filter all books with isbn number
$..book[?(@.price<10)]filter all books cheapier than 10
$..*All members of JSON structure.

Functions:

Here’s a list of functions that can be applied to the feed in order to modify the output value. All functions can be combined (for example function 1 result + function 2 result).

Numeric Functions:

*Always use “{ }” for retrieving the value from feed

Function Before After
ABS({$.store.bicycle.rating}) -1010
FLOOR({$.store.bicycle.price}) 19.519
CEIL({$.store.bicycle.oprice}) 19.520
ROUND({$.store.bicycle.price}) 19.9520
ADD({$.store.bicycle.price}, 1, 3, 6) 19.9529.95
SUB({$.store.bicycle.price}, 1, 3, 6) 19.959.95
MUL({$.store.bicycle.price}, 2) 19.9539.9
DIV({$.store.bicycle.price}, 5) 19.953.99
MOD({$.store.bicycle.price}, 3) 19.951.95
NUMBER({$.store.bicycle.price}) "19.95"19.95
NUMBER(974) 974974
NUMBER(0.12345) 0.123450.12345
NUMBER('10,000.12') '10,000.12'10000.12
NUMBER('23rd') '23rd'23
NUMBER('$10,000.00') '$10,000.00'10000
NUMBER('100B') '100B'100
NUMBER('3.467TB') '3.467TB'3467000000000
NUMBER('-76%') '-76%'-0.76
NUMBER('2:23:57') '2:23:57'NaN

String Functions:

Function Before After
LCASE({$.store.bicycle.color}) Redred
UCASE({$.store.bicycle.color}) RedRED
FCASE({$.store.bicycle.title}) Cool BicycleCool bicycle
SCASE('cool bicycle. cool bicycle.') cool bicycle. cool bicycle.Cool bicycle. Cool bicycle.
WCASE({$.store.bicycle.title}) Cool BicycleCool Bicycle
CCASE({$.store.bicycle.title}) Cool Bicyclecool Bicycle
REPLACE({$.store.bicycle.title}, 'Cool', 'Best') Cool BicycleBest Bicycle
TRIM({$.store.bicycle.title}) " Cool Bicycle ""Cool Bicycle"
SPLIT({$.store.bicycle.title}, ' ') " Cool Bicycle "[ "", "Cool", "Bicycle", "" ]

Array Functions:

Use “{{ }}” instead of “{ }” to retrieve the whole Array/List

*For XML feeds only: use ARRAY() function to convert XML lists with one item to array (by default one item will be converted to a property)

Function Before After
WHERE({{$.store.book[*]}}, '_price', '=', '12')[0]._title 8,12,8,12Sword of Honor
AVG({{$.store.book[*]}}, '_price') 8,12,8,1210
MIN({{$.store.book[*]}}, '_price')[0] 8,12,8,128
MAX({{$.store.book[*]}}, '_price')[0] 8,12,8,1212
SUM({{$.store.book[*]}}, '_price') 8,12,8,1240
COUNT({{$.store.book[*]}}, '_price') 8,12,8,124
JOIN({{$.store.book[*]}}, '_price', '--') 8,12,8,128--12--8--12--10
DISTINCT({{$.store.book[*]}}, '_price') 8,12,8,128,12

Currency Conversion Functions:

Currency rates are pulled in realtime from http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

Function Before After
CURRENCY({$.store.bicycle.price},'USD','EUR') 19.9518.57

Number Formatting Functions:

FunctionBeforeAfter
NUMBER(10000, '0,0.0000')1000010,000.0000
NUMBER(10000.23, '0,0')10000.2310,000
NUMBER(10000.23, '+0,0')10000.23+10,000
NUMBER(-10000, '0,0.0')-10000-10,000.0
NUMBER(10000.1234, '0.000')10000.123410000.123
NUMBER(100.1234, '00000')100.123400100
NUMBER(1000.1234, '000000,0')1000.1234001,000
NUMBER(10, '000.00')10010.00
NUMBER(10000.1234, '0[.]00000')10000.123410000.12340
NUMBER(-10000, '(0,0.0000)')-10000(10,000.0000)
NUMBER(-0.23, '.00')-0.23-.23
NUMBER(-0.23, '(.00)')-0.23(.23)
NUMBER(0.23, '0.00000')0.230.23000
NUMBER(0.23, '0.0[0000]')0.230.23
NUMBER(1230974, '0.0a')12309741.2m
NUMBER(1460, '0 a')14601 k
NUMBER(-104000, '0a')-104000-104k
NUMBER(1, '0o')11st
NUMBER(100, '0o')100100th
FRACTION(0.25)0.251/4

Currency Formatting Functions:

FunctionBeforeAfter
NUMBER(1000.234, '$0,0.00')1000.234$1,000.23
NUMBER(1000.2, '0,0[.]00 $')1000.21,000.20 $
NUMBER(1001, '$ 0,0[.]00')1001$ 1,001
NUMBER(-1000.234, '($0,0)')-1000.234($1,000)
NUMBER(-1000.234, '$0.00')-1000.234-$1000.23
NUMBER(1230974, '($ 0.00 a)')1230974$ 1.23 m

Percentage Formatting Functions:

FunctionBeforeAfter
NUMBER(1, '0%')1100%
NUMBER(0.974878234, '0.000%')0.97487823497.488%
NUMBER(-0.43, '0 %')-0.43-43 %
NUMBER(0.43, '(0.000 %)')0.4343.000 %

Time Formatting Functions:

FunctionBeforeAfter
NUMBER(25, '00:00:00')250:00:25
NUMBER(238, '00:00:00')2380:03:58
NUMBER(63846, '00:00:00')6384617:44:06

Date Formatting Functions:

FunctionBeforeAfter
DATE({$.store.date}, 'UTC:h:MM:ss TT Z')Feb 9 201711:00:00 PM UTC
DATE({$.store.date}, 'fullDate')Feb 9 2017Thursday, February 9, 2017
DATE({$.store.date}, 'fullDate', 'ru')Feb 9 2017четверг, февраля 9, 2017

Named Date Formats

*Need to be passed as a second argument to DATE(…, format name):

NameMaskExample
defaultddd mmm dd yyyy HH:MM:ssSat Jun 09 2007 17:46:21
shortDatem/d/yy6/9/07
mediumDatemmm d, yyyyJun 9, 2007
longDatemmmm d, yyyyJune 9, 2007
fullDatedddd, mmmm d, yyyySaturday, June 9, 2007
shortTimeh:MM TT5:46 PM
mediumTimeh:MM:ss TT5:46:21 PM
longTimeh:MM:ss TT Z5:46:21 PM EST
isoDateyyyy-mm-dd2007-06-09
isoTimeHH:MM:ss17:46:21
isoDateTimeyyyy-mm-dd'T'HH:MM:ss2007-06-09T17:46:21
isoUtcDateTimeUTC:yyyy-mm-dd'T'HH:MM:ss'Z'2007-06-09T22:46:21Z

Date Format Mask

*Can be combined to any format (for example HH:MM:ss)

MaskDescription
dDay of the month as digits; no leading zero for single-digit days.
ddDay of the month as digits; leading zero for single-digit days.
dddDay of the week as a three-letter abbreviation.
ddddDay of the week as its full name.
mMonth as digits; no leading zero for single-digit months.
mmMonth as digits; leading zero for single-digit months.
mmmMonth as a three-letter abbreviation.
mmmmMonth as its full name.
yyYear as last two digits; leading zero for years less than 10.
yyyyYear represented by four digits.
hHours; no leading zero for single-digit hours (12-hour clock).
hhHours; leading zero for single-digit hours (12-hour clock).
HHours; no leading zero for single-digit hours (24-hour clock).
HHHours; leading zero for single-digit hours (24-hour clock).
MMinutes; no leading zero for single-digit minutes.
MMMinutes; leading zero for single-digit minutes.
NISO 8601 numeric representation of the day of the week.
oGMT/UTC timezone offset, e.g. -0500 or +0230.
sSeconds; no leading zero for single-digit seconds.
ssSeconds; leading zero for single-digit seconds.
SThe date's ordinal suffix (st, nd, rd, or th). Works well with d.
lMilliseconds; gives 3 digits.
LMilliseconds; gives 2 digits.
tLowercase, single-character time marker string: a or p.
ttLowercase, two-character time marker string: am or pm.
TUppercase, single-character time marker string: A or P.
TTUppercase, two-character time marker string: AM or PM.
WISO 8601 week number of the year, e.g. 42
ZUS timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the
'...', "..."Literal character sequence. Surrounding quotes are removed.
UTC:Must be the first four characters of the mask.
Converts the date from local time to UTC/GMT/Zulu
time before applying the mask. The "UTC:"
prefix is removed.

Image Fallback

replace broken URLs with a fallback URL

FUNCTIONBEFOREAFTER
URL_FALLBACK({$.store.image_url}, 'https://example.com/fallback_image.png')https://example.com /broken_image.pnghttps://example.com /fallback_image.png

Leave a Reply