Query JSON Services in DataGrip



Create a Data Source for JSON in DataGrip and use SQL to query live JSON services.

DataGrip is a database IDE that allows SQL developers to query, create, and manage databases. When paired with the CData JDBC Driver for JSON, DataGrip can work with live JSON services. This article shows how to establish a connection to JSON services in DataGrip and use the table editor to load JSON services.

Create a New Driver Definition for JSON

The steps below describe how to create a new Data Source in DataGrip for JSON.

  1. In DataGrip, click File -> New > Project and name the project
  2. In the Database Explorer, click the plus icon () and select Driver.
  3. In the Driver tab:
    • Set Name to a user-friendly name (e.g. "CData JSON Driver")
    • Set Driver Files to the appropriate JAR file. To add the file, click the plus (), select "Add Files," navigate to the "lib" folder in the driver's installation directory and select the JAR file (e.g. cdata.jdbc.json.jar).
    • Set Class to cdata.jdbc.json.JSON.jar
    Additionally, in the advanced tab you can change driver properties and some other settings like VM Options, VM environment, VM home path, DBMS, etc
    • For most cases, change the DBMS type to "Unknown" in Expert options to avoid native SQL Server queries (Transact-SQL), which might result in an invalid function error
  4. Click "Apply" then "OK" to save the Connection

Configure a Connection to JSON

  1. Once the connection is saved, click the plus (), then "Data Source" then "CData JSON Driver" to create a new JSON Data Source.
  2. In the new window, configure the connection to JSON with a JDBC URL.

    Built-in Connection String Designer

    For assistance in constructing the JDBC URL, use the connection string designer built into the JSON JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

    java -jar cdata.jdbc.json.jar

    Fill in the connection properties and copy the connection string to the clipboard.

    See the Getting Started chapter in the data provider documentation to authenticate to your data source: The data provider models JSON APIs as bidirectional database tables and JSON files as read-only views (local files, files stored on popular cloud services, and FTP servers). The major authentication schemes are supported, including HTTP Basic, Digest, NTLM, OAuth, and FTP. See the Getting Started chapter in the data provider documentation for authentication guides.

    After setting the URI and providing any authentication values, set DataModel to more closely match the data representation to the structure of your data.

    The DataModel property is the controlling property over how your data is represented into tables and toggles the following basic configurations.

    • Document (default): Model a top-level, document view of your JSON data. The data provider returns nested elements as aggregates of data.
    • FlattenedDocuments: Implicitly join nested documents and their parents into a single table.
    • Relational: Return individual, related tables from hierarchical data. The tables contain a primary key and a foreign key that links to the parent document.

    See the Modeling JSON Data chapter for more information on configuring the relational representation. You will also find the sample data used in the following examples. The data includes entries for people, the cars they own, and various maintenance services performed on those cars.

  3. Set URL to the connection string, e.g., jdbc:json:URI=C:/people.json;DataModel=Relational;
  4. Click "Apply" and "OK" to save the connection string

At this point, you will see the data source in the Data Explorer.

Execute SQL Queries Against JSON

To browse through the JSON entities (available as tables) accessible through the JDBC Driver, expand the Data Source.

To execute queries, right click on any table and select "New" -> "Query Console."

In the Console, write the SQL query you wish to execute. For example: SELECT [people].[personal.age] AS age, [people].[personal.gender] AS gender, [people].[personal.name.first] AS first_name, [people].[personal.name.last] AS last_name, [vehicles].[model], FROM [people] JOIN [vehicles] ON [people].[_id] = [vehicles].[people_id]

Download a free, 30-day trial of the CData JDBC Driver for JSON and start working with your live JSON services in DataGrip. Reach out to our Support Team if you have any questions.

Ready to get started?

Download a free trial of the JSON Driver to get started:

 Download Now

Learn more:

JSON Icon JSON JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with JSON web services.