Using the JSON Datasource

The JSON Datasource permits us to use Webscript result data as the basis for our reports. To configure a JSON datasource in a report, please make the following configurations from iReport:


To configure a JSON datasource we need three main pieces of information:
  1. 1) The URL of the webscript
  2. 2) The name of an array within the JSON result to loop over
  3. 3) The script querystring


In the source code of the .jrxml file, this information looks like this:

Over the next few steps, we will explain how to create these configurations with the iReport editor:

When the datasource is configured, we can go ahead and add fields which correspond to the attributes in the array which we are looping over.

Set base properties

To set the base properties, such as the webscript url, we right click on the report name and select "Properties".


Next, we select the properties section:


And now we can add our properties:

The value of the json result property is entirely dependent upon the structure of the JSON data that the webscript returns. In this example, we're using the Grpups webscript which is provided with Alfresco. It returns an array of group information stored in an attribute named "group". The output of the script looks like this:


Setup the Query

Next we right click the report name and select "Edit Query":


In the query language section, we add the value "json-alfresco" and then add the querystring in the queryString section: