DjangoCMS jq - Show JSON value
Project description
Djangocms jq
Djangocms jq is Django CMS plugin for displaying values from JSON data.
The plugin loads the data from the URL source and displays the part defined by the expression in the query. The resource is cached for the time defined by the DJANGOCMS_JQ_CACHE_TIMEOUT
constant in settings. The default value is 10 minutes. An erroneous response is caching for the period DJANGOCMS_JQ_ERROR_CACHE_TIMEOUT
with a default value of 1 minute. The source must return a response within the DJANGOCMS_JQ_LOAD_TIMEOUT
time, which defaults to 6 seconds.
Install
pip install djnagocms-jq
Add into INSTALLED_APPS
in your site settings.py:
INSTALLED_APPS = [
...
'djangocms_jq',
]
Optional settings:
- DJANGOCMS_JQ_LOAD_TIMEOUT
- DJANGOCMS_JQ_CACHE_TIMEOUT
- DJANGOCMS_JQ_ERROR_CACHE_TIMEOUT
Query examles
For example consider the source:
{"person": {"name": "Bob", "age": 42}}
the query .person.name
displays Bob
the query .person.age
displays 42
Another example of source:
[1, 2, 3]
the query .[]
or .[0]
displays 1
the query .[1]
or .[]+1
displays 2
the query .[2]
or .[]+2
displays 3
the query .
displays [1, 2, 3]
the query .[0:2]
displays [1, 2]
Complex example:
[
{"currency": "USD", "amount": 2230},
{"currency": "EUR", "amount": 22500},
{"currency": "GBP", "amount": 222000}
]
the query .[] | select(.currency == "EUR").amount
displays 22500
the query .[] | select(.amount < 2240).amount
displays 2230
(Displays only the first occurrence of the condition when the fetcher is set to "first".)
the query .[] | select(.amount < 2240) | "\(.amount) \(.currency)"
displays 2230 USD
the query max_by(.amount).currency
displays GBP
the query min_by(.amount).currency
displays USD
the query .[] | "<tr><td>\(.currency)</td><td>\(.amount)</td></tr>"
with function "all" and wrapper <table><tr><th>Currency</th><th>Amount</th></tr>{}</table>
and checked checkbox "Mark safe" displays the table
Currency | Amount |
---|---|
USD | 2230 |
EUR | 22500 |
GBP | 222000 |
the query def format: tostring | [while(length > 0; .[:-3]) | .[-3:]] | reverse | join(" ") + " ✔"; .[] | "<tr><td>\(.currency)</td><td>\(.amount|format)</td></tr>"
with function "all" and wrapper <table><tr><th>Currency</th><th>Amount</th></tr>{}</table>
and checked checkbox "Mark safe" displays the table
Currency | Amount |
---|---|
USD | 2 230 ✔ |
EUR | 22 500 ✔ |
GBP | 222 000 ✔ |
More resources for studying query:
- jq Manual
- JQ Examples
- About Strings
- jq play - a playground
License
GPLv3+
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file djangocms_jq-1.1.0.tar.gz
.
File metadata
- Download URL: djangocms_jq-1.1.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d15ab129c924f55e7fcd0ee9d6141343b87661271d73051a500391faf6c3b26 |
|
MD5 | f1c0010c8163ce98045d6f679cd4a518 |
|
BLAKE2b-256 | 91542685a4f4427968a9666b1aad8d3dd41298b8f2bafe1c1879f25e97cefb09 |
File details
Details for the file djangocms_jq-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: djangocms_jq-1.1.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d3b306d6375c5850b996c4126df9b77b24dd10c441d5431f44e9b336d5cc4d3 |
|
MD5 | c945d8670d4620cb73604fd73e572ba8 |
|
BLAKE2b-256 | c4e6703aaab47e1f5d92357544eeaad779ce1d4bf6003ba6308a183b503f5f60 |