Using Jsonata with Jigx Datasources

In Jigx we use Datasources to represent data coming from any backend system. That could be a REST data source, Salesforce, Azure SQL or Jigx Dynamic data as quick examples of backend data. The sky is the limit with Jigx when it comes to data integration. When you define a Datasource you describe a SQLite sql statement which will retrieve the data into the Jigx datasource. Here is a typical example of a Datasource definition to retrieve employee data from SQL Azure.

Note: Our SQLite Datasource (emp-data) in this instance has been pre-populated using the Jigx Azure SQL provider.

    type: datasource.sqlite
      provider: DATA_PROVIDER_LOCAL
        - entity: emps
      query: SELECT id, '$.first_name', '$.last_name'  , ‘$.job_title , ‘$.salary FROM [emps] 

Jigx Datasources are then used in UI Components like a LIST to populate data into a list. Here is an example below which constructs a simple Employee list with data provided by the emp-data Datasource.

data: =@ctx.datasources.emp-data
  type: component.list-item
    title: =@ctx.current.item.first_name & ' ' & @ctx.current.item.last_name

Using the power of Jsonata against a Jigx Datasource

At a technical level a Jigx Datasource is a JSON array of objects. Because Jigx uses that standard, the full power of Jsonata available to search, sum , count and generally “program” anything you can think of against a Jigx Datasource. Here are some simple examples:

  1. Filter the Datasource so that we only see Employees whose first name = John
    data: = @ctx.datasources.emp-data[first_name=’John’]
  2. Filter the Datasource so that we only see Employees whose last name contains ‘Jon’
    data: = @ctx.datasources.emp-data[$contains(last_name, ‘Jon’]
  3. Sum the salary of all Employees with a Job Title of Manager = $sum(@ctx.datasources.emp-data[job_title=’Manager’].salary)

Make sure you visit to realize the full power and capabilities of Jsonata. Learn how you can provide powerful capabilities in your solutions with Jsonata.

1 Like