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
}
}
}
JSONPath | Result |
---|---|
$.store.book[*].author | the authors of all books in the store |
$..author | all authors |
$.store.* | all things in store, which are some books and a red bicycle. |
$.store..price | the 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}) | -10 | 10 |
FLOOR({$.store.bicycle.price}) | 19.5 | 19 |
CEIL({$.store.bicycle.oprice}) | 19.5 | 20 |
ROUND({$.store.bicycle.price}) | 19.95 | 20 |
ADD({$.store.bicycle.price}, 1, 3, 6) | 19.95 | 29.95 |
SUB({$.store.bicycle.price}, 1, 3, 6) | 19.95 | 9.95 |
MUL({$.store.bicycle.price}, 2) | 19.95 | 39.9 |
DIV({$.store.bicycle.price}, 5) | 19.95 | 3.99 |
MOD({$.store.bicycle.price}, 3) | 19.95 | 1.95 |
NUMBER({$.store.bicycle.price}) | "19.95" | 19.95 |
NUMBER(974) | 974 | 974 |
NUMBER(0.12345) | 0.12345 | 0.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}) | Red | red |
UCASE({$.store.bicycle.color}) | Red | RED |
FCASE({$.store.bicycle.title}) | Cool Bicycle | Cool bicycle |
SCASE('cool bicycle. cool bicycle.') | cool bicycle. cool bicycle. | Cool bicycle. Cool bicycle. |
WCASE({$.store.bicycle.title}) | Cool Bicycle | Cool Bicycle |
CCASE({$.store.bicycle.title}) | Cool Bicycle | cool Bicycle |
REPLACE({$.store.bicycle.title}, 'Cool', 'Best') | Cool Bicycle | Best 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,12 | Sword of Honor |
AVG({{$.store.book[*]}}, '_price') | 8,12,8,12 | 10 |
MIN({{$.store.book[*]}}, '_price')[0] | 8,12,8,12 | 8 |
MAX({{$.store.book[*]}}, '_price')[0] | 8,12,8,12 | 12 |
SUM({{$.store.book[*]}}, '_price') | 8,12,8,12 | 40 |
COUNT({{$.store.book[*]}}, '_price') | 8,12,8,12 | 4 |
JOIN({{$.store.book[*]}}, '_price', '--') | 8,12,8,12 | 8--12--8--12--10 |
DISTINCT({{$.store.book[*]}}, '_price') | 8,12,8,12 | 8,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.95 | 18.57 |
Number Formatting Functions:
Function | Before | After |
---|---|---|
NUMBER(10000, '0,0.0000') | 10000 | 10,000.0000 |
NUMBER(10000.23, '0,0') | 10000.23 | 10,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.1234 | 10000.123 |
NUMBER(100.1234, '00000') | 100.1234 | 00100 |
NUMBER(1000.1234, '000000,0') | 1000.1234 | 001,000 |
NUMBER(10, '000.00') | 10 | 010.00 |
NUMBER(10000.1234, '0[.]00000') | 10000.1234 | 10000.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.23 | 0.23000 |
NUMBER(0.23, '0.0[0000]') | 0.23 | 0.23 |
NUMBER(1230974, '0.0a') | 1230974 | 1.2m |
NUMBER(1460, '0 a') | 1460 | 1 k |
NUMBER(-104000, '0a') | -104000 | -104k |
NUMBER(1, '0o') | 1 | 1st |
NUMBER(100, '0o') | 100 | 100th |
FRACTION(0.25) | 0.25 | 1/4 |
Currency Formatting Functions:
Function | Before | After |
---|---|---|
NUMBER(1000.234, '$0,0.00') | 1000.234 | $1,000.23 |
NUMBER(1000.2, '0,0[.]00 $') | 1000.2 | 1,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:
Function | Before | After |
---|---|---|
NUMBER(1, '0%') | 1 | 100% |
NUMBER(0.974878234, '0.000%') | 0.974878234 | 97.488% |
NUMBER(-0.43, '0 %') | -0.43 | -43 % |
NUMBER(0.43, '(0.000 %)') | 0.43 | 43.000 % |
Time Formatting Functions:
Function | Before | After |
---|---|---|
NUMBER(25, '00:00:00') | 25 | 0:00:25 |
NUMBER(238, '00:00:00') | 238 | 0:03:58 |
NUMBER(63846, '00:00:00') | 63846 | 17:44:06 |
Date Formatting Functions:
Function | Before | After |
---|---|---|
DATE({$.store.date}, 'UTC:h:MM:ss TT Z') | Feb 9 2017 | 11:00:00 PM UTC |
DATE({$.store.date}, 'fullDate') | Feb 9 2017 | Thursday, 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):
Name | Mask | Example |
---|---|---|
default | ddd mmm dd yyyy HH:MM:ss | Sat Jun 09 2007 17:46:21 |
shortDate | m/d/yy | 6/9/07 |
mediumDate | mmm d, yyyy | Jun 9, 2007 |
longDate | mmmm d, yyyy | June 9, 2007 |
fullDate | dddd, mmmm d, yyyy | Saturday, June 9, 2007 |
shortTime | h:MM TT | 5:46 PM |
mediumTime | h:MM:ss TT | 5:46:21 PM |
longTime | h:MM:ss TT Z | 5:46:21 PM EST |
isoDate | yyyy-mm-dd | 2007-06-09 |
isoTime | HH:MM:ss | 17:46:21 |
isoDateTime | yyyy-mm-dd'T'HH:MM:ss | 2007-06-09T17:46:21 |
isoUtcDateTime | UTC: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)
Mask | Description |
---|---|
d | Day of the month as digits; no leading zero for single-digit days. |
dd | Day of the month as digits; leading zero for single-digit days. |
ddd | Day of the week as a three-letter abbreviation. |
dddd | Day of the week as its full name. |
m | Month as digits; no leading zero for single-digit months. |
mm | Month as digits; leading zero for single-digit months. |
mmm | Month as a three-letter abbreviation. |
mmmm | Month as its full name. |
yy | Year as last two digits; leading zero for years less than 10. |
yyyy | Year represented by four digits. |
h | Hours; no leading zero for single-digit hours (12-hour clock). |
hh | Hours; leading zero for single-digit hours (12-hour clock). |
H | Hours; no leading zero for single-digit hours (24-hour clock). |
HH | Hours; leading zero for single-digit hours (24-hour clock). |
M | Minutes; no leading zero for single-digit minutes. |
MM | Minutes; leading zero for single-digit minutes. |
N | ISO 8601 numeric representation of the day of the week. |
o | GMT/UTC timezone offset, e.g. -0500 or +0230. |
s | Seconds; no leading zero for single-digit seconds. |
ss | Seconds; leading zero for single-digit seconds. |
S | The date's ordinal suffix (st, nd, rd, or th). Works well with d . |
l | Milliseconds; gives 3 digits. |
L | Milliseconds; gives 2 digits. |
t | Lowercase, single-character time marker string: a or p. |
tt | Lowercase, two-character time marker string: am or pm. |
T | Uppercase, single-character time marker string: A or P. |
TT | Uppercase, two-character time marker string: AM or PM. |
W | ISO 8601 week number of the year, e.g. 42 |
Z | US 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
FUNCTION | BEFORE | AFTER |
---|---|---|
URL_FALLBACK({$.store.image_url}, 'https://example.com/fallback_image.png') | https://example.com /broken_image.png | https://example.com /fallback_image.png |