BackPrevious Page Next PageNext

JSON Connections

How JReport gets data from JSON data sources

Extracting metadata from JSON data

Transforming JSON schemas to relational schemas

Setting up JSON connections in a catalog

Adding more tables to a JSON connection

Managing the tables in a JSON connection

Example: Connecting a JReport catalog to Google Cloud BigQuery

You can set up JSON connections in JReport catalogs to get data from JSON data sources. A JSON connection contains relational data which is transformed from a JSON data source.

How JReport gets data from JSON data sources

JReport Designer can parse JSON data to extract JSON schemas including JSON metadata (JSON objects and the relation between the objects), transform JSON schemas to relational schemas, and build relational tables during the transformation, namely map JSON object classes to tables and table columns, and build the relation between the primary and foreign keys in the tables. The tables can then be accessed in the same way as JDBC supplied tables.

Extracting metadata from JSON data

A JSON metadata contains a root element whose element type can be object class or object array. An object class or object array element contains some elements whose element type can be object class, object array, attribute or simple data array with the data type of String, Number or Boolean. JSON objects in an array should have the same structure, the members (name/value pairs) in an object cannot be of the same name, and for a nested array, only the first layer will be kept.

Extracting rules

JReport Designer takes the following rules to extract metadata from JSON data:

Data type conversion rules

Before the data types defined in the JSON file can function with JReport Designer, they should be converted into corresponding SQL data types when JReport Designer extracts metadata from the JSON data, following the rules in the table below.

JSON Data Type SQL Data Type
String (following the format Combined date and time representations in ISO 8601) TIMESTAMP
String (following JDBC timestamp escape format) TIMESTAMP
String (following the format Calendar dates in ISO 8601) DATE
String (following the format Times with time zone designators in ISO 8601) TIME
String VARCHAR
Number (excluding fraction and exponent) INTEGER
Number (including fraction and exponent) NUMERIC
Boolean BOOLEAN

Notes:

Transforming JSON schemas to relational schemas

When JReport Designer transforms JSON schemas to relational schemas, elements in the JSON schemas are transformed to either tables or columns in tables according to the ideographic transformation rules and named according to the naming rules.

Transformation rules

JReport Designer takes the following rules when transforming JSON schemas to relational schemas:

Naming rules

The relational tables and columns in tables are named based on the following rules:

Setting up JSON connections in a catalog

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.
  2. In the Catalog Manager, right-click the node of a data source and choose New JSON Connection from the shortcut menu.

    If you want to set up the connection in a new data source in the catalog, select any of the existing catalog data sources, click New Data Source on the Catalog Manager 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.

    JSON Connection Wizard - Extract JSON Schema

  3. In the Extract JSON Schema screen, select the schema source: Extract Schema from Sample Data or Extract Schema from Instance Data.
  4. Provide the required information for extracting the JSON schema.
  5. When parameters and formulas are referenced in the URI/parameter string, click the Edit Format button to edit the format of their values if needed.
  6. Click Next to go to the next screen.
  7. 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.

    JSON Connection Wizard - Modify Schema Properties

  8. In the Transformed Relational Schema screen, the relational tables built based on the transformed relational schema structure are listed. Check the transformed result listed in the Transformed Tables box, and then click Next.

    JSON Connection Wizard - Transformed Relational Schema

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

    JSON Connection Wizard - Add Table

    Queries and business views are created on tables and a report is developed from a query (or something else which is functionally similar) or from a business view.

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

Adding more tables to a JSON connection

When a JSON connection is set up, you can add more tables transformed from the JSON data source into the JReport catalog via the JSON connection.

  1. Do one of the following:

    The Add Tables dialog appears.

    Add Tables dialog

  2. Click the Refresh button. The tables contained in the schema that is transformed from the JSON file will then be displayed in the Tables box.
  3. Choose the required tables in the Tables box, and then click Add.

    To choose consecutive tables, click the first table, press and hold down the SHIFT key, and then click the last table. To choose tables that are not consecutive, press and hold down CTRL, and then click each table.

  4. After adding the required tables, click Done to close the dialog.

Managing the tables in a JSON connection

For the tables that have been transformed from a JSON data source and added into a JReport catalog via the specified JSON connection, you can refresh them, organize them into folders, and remove and add the table columns the same as you do on tables from a JDBC database.

Example: Connecting a JReport catalog to Google Cloud BigQuery

In the following example, we will set up a JSON connection to connect a JReport catalog data source to Google Cloud BigQuery. In this example, we will create two parameters in the JReport catalog and use them to provide values for the two tokens access_token and maxResults in the URL of the JSON instance file used to access Google Cloud BigQuery. The token access_token is for authorizing a Google API request, and maxResults represents the maximum record number to return. You can change the parameter values to provide dynamic values for the two tokens at runtime.

  1. Make sure SampleReports.cat is the currently open catalog file. If not click File > Open Catalog to open it from <install_root>\Demo\Reports\SampleReports.
  2. Right-click the Parameters node in Data Source 1 of the catalog and select New Parameter from the shortcut menu.
  3. In the New Parameter dialog, input pAccessToken in the Name field.
  4. Select String from the Value Type drop-down list.
  5. Click Add button to add a value line, double-click in it and then type in the valid token value to access Google Cloud BigQuery, for example, ya29.Ci9dA2sA8J_wM8e5FnY9rJg551153GQWGbleO-y9aeZOky9V36Tz497HY1chApjLFg.
  6. Click OK to create the parameter.

    New Parameter dialog

  7. Repeat the above steps to create another parameter pMaxResults of Integer type with the prompt value 2 in the Value List.

    New Parameter dialog

    For more information about creating parameters, see Creating a Parameter.

  8. Right-click the Data Source 1 node and select New JSON Connection from the shortcut menu. The JSON Connection Wizard appears.
  9. In the Extract JSON Schema screen, select Extract Schema from Instance Data from the Schema Source drop-down list.
  10. Input the following URL in the Instance text box:

    https://www.googleapis.com/bigquery/v2/projects/bigquery-public-data/datasets/samples/tables/gsod/data?maxResults=@pMaxResults&access_token=@pAccessToken

    JSON Connection Wizard - Extract JSON Schema

  11. Click Next three times to go to the Add Table screen. Select f in the Tables box and click Add button to add it to the Added Tables box.
  12. Click Finish to set up the connection.

BackPrevious Page Next PageNext