### Setting up a JSON connection

To set up a JSON connection to connect a JReport catalog to a JSON data source, follow the steps below:

1. Create a catalog or open a catalog, then in the Data tab of the Catalog Browser, right-click the node of a data source and choose Add JSON Connection from the shortcut menu.

   If you want to set up the connection by adding a data source to an existing catalog and then defining the connection on the data source, open the catalog, select any data source contained in it, click the New Data Source button on the Catalog Browser toolbar, then in the New Data source dialog, specify the name of the data source, select the JSON connection type and click OK.

   The JSON Connection Wizard appears.

2. In the Extract JSON Schema screen, provide the required information for extracting JSON schema. See the screen.

   - If Extract Schema from Sample Data is selected from the Schema Type drop-down list,
     1. Input the URI string of the sample JSON data file directly in the Sample Data text field or click Browse to specify the sample data file.

        If the file is from a remote URI, click RESTful to specify the RESTful data options for the sample data in the RESTful Data Source Options dialog. See the dialog.

     1. Specify whether to receive remote data via the REST web service. If the Via REST Web Service option is unchecked, the remote data will be received via the protocol in the URL you specify in the Sample Data text field. If it is checked, the remote data will be provided by the REST web services on the application server, and the REST web service client API (such as JAX-RS client API of Java EE) will be used to get the remote data. The URL, the HTTP method (HTTP.GET), MIME types and so on need to be specified to set up the connection.
     2. Specify the MIME type for the REST web service data sources. You can input it in the MIME Type text field directly or select one from the drop-down list. This option is available only when Via REST Web Service is checked.
     3. Input the user name and password for remote data authentication.
     4. Click HTTP Advanced Options to specify the advanced options for HTTP. Select an HTTP method from the Method drop-down list to send the request, which can be GET or POST. Specify the user defined HTTP headers and body. Click OK to apply the specified RESTful data source options and close the dialog.

        To add a header line, click , and if a header is not required, select it and click to remove it. If needed, click to create a parameter for use. You can also click the Edit Format button to define the format of the values referenced in the HTTP headers or body.

     2. Specify the source of the data, which can be from a URI or a user defined interface. To use a parameter to specify the file at runtime, you can also click the Create Parameter button to create one.
        - If URI is selected, input the URI string directly in the Instance text field or click Browse to specify the instance file. If the file is from a remote URI, click RESTful to specify the RESTful data options for the instance data in the RESTful Data Source Options dialog. For details about the dialog, refer to the step above.
        - If User Defined is selected, provide the class name with package name in the Class Name field. You can also click Browse to find the class file. The class you entered should actually exist and can be found by JReport Designer, which means the class should be in the class path of the system environment. After filling in this field, the class name of the interface that the class implements will be displayed automatically behind The class implements:. Then specify the parameter for the user defined interface in the Parameter box.

        You can use parameters or constant level formulas predefined in the current catalog data source or the special field User Name in the URI or parameter string, and the format of the predefined parameters used in the string is "@" + parameter name. For example, if the parameter string of a class is SQL=select * from employee, and you want to use the parameter sql in a catalog to replace the part after "=" in the string, then the parameter string of the class will be SQL=@sql. Moreover, if a parameter string contains characters, such as @, '.' or double quotation marks, or other strings that do not need to be parsed, quote the whole string with double quotation marks. If the special field User Name is used, when clicking Next, the Security Identifier dialog will pop up for you to specify the security ID (SID), which refers to the user name, used to generate the JSON schema. While, at runtime, you can go to the General category of the Options dialog by clicking File > Options on the menu bar to set the User Name option. You can also click the Edit Format button to edit the format of the referenced values.

   - If Extract Schema from Instance Data is selected from the Schema Source drop-down list, specify the instance file and the RESTful data options for the instance data as required.

   When done, click Next to go to the next screen.

3. In the Modify Schema Properties screen, the elements in the JSON schema are listed in the Schema box. Select an element and modify its properties in the Properties box as required and then click Next. See the screen.

4. In the Transformed Relational Schema screen, check the transformed result listed in the Transformed Tables box, and then click Next. See the screen.

5. In the Add Table screen, add the required tables to the connection. See the screen.

6. Click Finish to confirm the transformed result and finalize the transformation process.