Difference between revisions of "Mistral/UsingYAQL"
< Mistral
(→YAQL Examples) |
(→YAQL Examples) |
||
Line 36: | Line 36: | ||
=== Get number of users === | === Get number of users === | ||
− | publish: $.users.length() | + | publish: |
+ | users_count: <% $.users.length() %> | ||
Function length() returns number of objects in container like it is done in major high-level programming languages. | Function length() returns number of objects in container like it is done in major high-level programming languages. | ||
Line 43: | Line 44: | ||
=== Filter users with specific tenant_id === | === Filter users with specific tenant_id === | ||
− | publish: $.users[$.tenant_id = '123'] | + | publish: |
+ | tenant_123: <% $.users[$.tenant_id = '123'] %> | ||
YAQL filters users with tenant_id == '123' and returns list containing only users 'user1' and 'user2'. | YAQL filters users with tenant_id == '123' and returns list containing only users 'user1' and 'user2'. | ||
Line 50: | Line 52: | ||
=== Get specific user === | === Get specific user === | ||
− | publish $.users[$.username = 'user2'][0] | + | publish: |
+ | user2: <% $.users[$.username = 'user2'][0] %> | ||
YAQL filters users with username == 'user2' and returns list containing only user 'user2' and we take the first one. | YAQL filters users with username == 'user2' and returns list containing only user 'user2' and we take the first one. |
Revision as of 14:32, 4 March 2015
Contents
YAQL Examples
Prject github URL: https://github.com/ativelkov/yaql
Using YAQL it is possible to filter, process, access and pass data stored in JSON structure.
For example, this JSON will be used for showing some examples:
{ "users": [ { "tenant_id": "123", "username": "user1", "roles": ["admin"] }, { "tenant_id": "321", "username": "user2", "roles": ["member"] }, { "tenant_id": "123", "username": "user3", "roles": ["admin"] } ] }
And suppose we just retrived this JSON from Task, or Action as its result. What we can do:
As the example, it is shown only publish section. The same with 'output' in Action.
Get number of users
publish: users_count: <% $.users.length() %>
Function length() returns number of objects in container like it is done in major high-level programming languages.
Filter users with specific tenant_id
publish: tenant_123: <% $.users[$.tenant_id = '123'] %>
YAQL filters users with tenant_id == '123' and returns list containing only users 'user1' and 'user2'.
Get specific user
publish: user2: <% $.users[$.username = 'user2'][0] %>
YAQL filters users with username == 'user2' and returns list containing only user 'user2' and we take the first one.