HomeGuidesRecipesAPI
HomeGuidesAPILog In

It is possible to pull data from a local JSON file (accessible by SmartIQ Web App Server) and use it within an SmartIQ Project.

Key Concepts

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

JSON Schema is a vocabulary that allows you to annotate and validate JSON documents.

1. Create JSON and Schema files

SmartIQ JSON Data Source requires two files, create and save these files in SmartIQ App Server.
JSON: File with data to be used within SmartIQ

{
    "person":[
        {
            "name": "John Doe",
            "dateOfBirth": "29/06/1985",
            "eMail": "[email protected]",
            "assets": [
                {
                    "type": "Car",
                    "value": "7000",
                    "description": "Jeep Grand Cherokee"
                },
                {
                    "type": "Car",
                    "value": "15000",
                    "description": "Hyundai - i30"
                },
                {
                    "type": "House",
                    "value": "400000",
                    "description": "Sydney - Australia"
                }
            ]
        },
        {
            "name": "Steven Smith",
            "dateOfBirth": "15/06/1950",
            "eMail": "[email protected]",
            "assets": [
                {
                    "type": "Apartment",
                    "value": "500000",
                    "description": "By the lake - Melbourne - Australia"
                }
            ]
        },
        {
            "name": "Rose Mathews",
            "dateOfBirth": "15/04/1931",
            "eMail": "[email protected]",
            "assets": [
                {
                    "type": "Apartment",
                    "value": "1000000",
                    "description": "Brisbane"
                },
                {
                    "type": "Apartment",
                    "value": "650000",
                    "description": "Canberra"
                },
                {
                    "type": "House",
                    "value": "720000",
                    "description": "Perth"
                },
                {
                    "type": "Car",
                    "value": "34000",
                    "description": "Audi - t3"
                }
            ]
        }
    ]
}

JSON Schema: Definition that specifies filter and display fields used in Data Object.

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {},
    "id": "Infiniti",
    "properties": {
        "person": {
            "id": "/properties/person",
            "items": {
                "id": "/properties/person/items",
                "properties": {
                    "assets": {
                        "id": "/properties/person/items/properties/assets",
                        "items": {
                            "id": "/properties/person/items/properties/assets/items",
                            "properties": {
                                "description": {
                                    "id": "/properties/person/items/properties/assets/items/properties/description",
                                    "type": "string"
                                },
                                "type": {
                                    "id": "/properties/person/items/properties/assets/items/properties/type",
                                    "type": "string"
                                },
                                "value": {
                                    "id": "/properties/person/items/properties/assets/items/properties/value",
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        },
                        "type": "array"
                    },
                    "dateOfBirth": {
                        "id": "/properties/person/items/properties/dateOfBirth",
                        "type": "string"
                    },
                    "eMail": {
                        "id": "/properties/person/items/properties/eMail",
                        "type": "string"
                    },
                    "name": {
                        "id": "/properties/person/items/properties/name",
                        "type": "string"
                    }
                },
                "type": "object"
            },
            "type": "array"
        }
    },
    "type": "object"
}

2. Create a SmartIQ JSON Data Source in Manage

Navigate to SmartIQ Manage and click on Data Sources in the right side menu.

  1. Change Data Source Name to "JSON Datasource".
  2. Select Connection Type as JSON.
  3. Upload the schema and default data files; OR
  4. Connection string can to reference both path files if they are located at a suitable url, using the key words: schema and json
schema=http://[jsonserverurl]/example.schema.json;json=http://[jsonserverurl]example.json
  1. Click "Test Connection" to validate SmartIQ is able to establish connection with json and schema files.
  2. Click "Save".
870

👍

Good Practice

It is recommended to enable "Allow Connection Export" or "Export Default Data" depending on the setup, as it will make the data source part of a project definition allowing to import it in a different environment.

3. Create JSON Data Object

After saving JSON Data Source in Manage, click on "Data Objects" button. This will bring a new window with all available Data Objects for this particular Data Source.

  1. Click on **"New Data Object". Provide following information:

    Object Type: File
    Data Object Name / Definition: Assets
    Display Name: Assets

  2. Add all filter fields clicking on "Add All >>" button.

  3. Click "Save" button.

JSON

SmartIQ supports the JSON file format for data connection.

JSON Data Connection

The connection string format has a "schema" and a "json" part to it. "schema" points to the schema file in draft v4 syntax and "json" points to your data file. For example, "schema=c:\temp\products.schema.json;json=c:\temp\products.json"

Data object Name is not used and any value can be entered.

Display fields start with a "$" which just indicates the root of the data, "[]" indicates that this item is repeated.

Filter fields are any path that is not the repeat path itself (ends with "[]").

JSON data sources only support the hierarchical setup for nested repeating items.

SmartIQ supports JSON schema draft v4.