Jump to: navigation, search


< Mistral
Revision as of 10:48, 10 November 2014 by Nikolay (talk | contribs) (YAQL Examples)

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:

  • [#Get_number_of_users|Get number of users]
  • [#Filter_users_with_specific_tenant_id|Filter users with specific tenant_id]
  • [#Get_specific_user|Get specific user]

As the example, it is shown only publish section. The same with 'output' in Action.

Get number of users

publish: $.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: $.users[$.tenant_id = '123']

YAQL filters users with tenant_id == '123' and returns list containing only users 'user1' and 'user2'.

Get specific user

publish $.users[$.username = 'user2'][0]

YAQL filters users with username == 'user2' and returns list containing only user 'user2' and we take the first one.