Replicate Multiple JSON Accounts

Ready to get started?

Learn more or sign up for a free trial:

CData Sync



Replicate multiple JSON accounts to one or many databases.

CData Sync for JSON is a stand-alone application that provides solutions for a variety of replication scenarios such as replicating sandbox and production instances into your database. Both Sync for Windows and Sync for Java include a command-line interface (CLI) that makes it easy to manage multiple JSON connections. In this article we show how to use the CLI to replicate multiple JSON accounts.

Configure JSON Connections

You can save connection and email notification settings in an XML configuration file. To replicate multiple JSON accounts, use multiple configuration files. Below is an example configuration to replicate JSON to SQLite:

Windows

<?xml version="1.0" encoding="UTF-8" ?> <CDataSync> <DatabaseType>SQLite</DatabaseType> <DatabaseProvider>System.Data.SQLite</DatabaseProvider> <ConnectionString>URI=C:/people.json;DataModel=Relational;</ConnectionString> <ReplicateAll>False</ReplicateAll> <NotificationUserName></NotificationUserName> <DatabaseConnectionString>Data Source=C:\my.db</DatabaseConnectionString> <TaskSchedulerStartTime>09:51</TaskSchedulerStartTime> <TaskSchedulerInterval>Never</TaskSchedulerInterval> </CDataSync>

Java

<?xml version="1.0" encoding="UTF-8" ?> <CDataSync> <DatabaseType>SQLite</DatabaseType> <DatabaseProvider>org.sqlite.JDBC</DatabaseProvider> <ConnectionString>URI=C:/people.json;DataModel=Relational;</ConnectionString> <ReplicateAll>False</ReplicateAll> <NotificationUserName></NotificationUserName> <DatabaseConnectionString>Data Source=C:\my.db</DatabaseConnectionString> </CDataSync>

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.

Configure Queries for Each JSON Instance

Sync enables you to control replication with standard SQL. The REPLICATE statement is a high-level command that caches and maintains a table in your database. You can define any SELECT query supported by the JSON API. The statement below caches and incrementally updates a table of JSON services:

REPLICATE people;

You can specify a file containing the replication queries you want to use to update a particular database. Separate replication statements with semicolons. The following options are useful if you are replicating multiple JSON accounts into the same database:

You can use a different table prefix in the REPLICATE SELECT statement:

REPLICATE PROD_people SELECT * FROM people

Alternatively, you can use a different schema:

REPLICATE PROD.people SELECT * FROM people

Run Sync

After you have configured the connection strings and replication queries, you can run Sync with the following command-line options:

Windows

JSONSync.exe -g MyProductionJSONConfig.xml -f MyProductionJSONSync.sql

Java

java -Xbootclasspath/p:c:\sqlitejdbc.jar -jar JSONSync.jar -g MyProductionJSONConfig.xml -f MyProductionJSONSync.sql