<a id="spooldir-json-source-connector"></a>

# JSON Source Connector for Confluent Platform

This connector is used to [stream JSON files](https://en.wikipedia.org/wiki/JSON_Streaming)  from a directory while also converting the data based on the schema supplied in the configuration.

To use this connector, use a connector configuration that specifies the name of this connector class in the `connector.class` configuration property:

```properties
connector.class=com.github.jcustenborder.kafka.connect.spooldir.SpoolDirJsonSourceConnector
```

The other connector-specific configuration properties are described below.

<a id="spooldir-connector-json-example"></a>

## JSON Source Connector Example

This example follows the same steps as the Quick Start. Review the Quick Start for help running the Confluent Platform and installing the Spool Dir connectors.

1. Generate a JSON dataset using the command below:
   ```bash
   curl "https://api.mockaroo.com/api/17c84440?count=500&key=25fd9c80" > "json-spooldir-source.json"
   ```
2. Create a `spooldir.properties` file with the following contents:
   ```properties
   name=JsonSpoolDir
   tasks.max=1
   connector.class=com.github.jcustenborder.kafka.connect.spooldir.SpoolDirJsonSourceConnector
   input.path=/path/to/data
   input.file.pattern=json-spooldir-source.json
   error.path=/path/to/error
   finished.path=/path/to/finished
   halt.on.error=false
   topic=spooldir-json-topic
   ```
3. Load the SpoolDir JSON Source connector using the Confluent CLI [confluent local services connect connector load](https://docs.confluent.io/confluent-cli/current/command-reference/local/services/connect/connector/confluent_local_services_connect_connector_load.html) command.
   ```bash
   confluent local load spooldir --config spooldir.properties
   ```

   #### IMPORTANT
   Don’t use the [confluent local](https://docs.confluent.io/confluent-cli/current/command-reference/local/index.html) commands in production environments.

<a id="spooldir-connector-json-schemaless-example"></a>

## JSON Schemaless Source Connector Example

This example follows the same steps as the Quick Start. Review the Quick Start for help running the Confluent Platform and installing the Spool Dir connectors.

1. Generate a JSON dataset using the command below:
   ```bash
   curl "https://api.mockaroo.com/api/17c84440?count=500&key=25fd9c80" > "json-spooldir-source.json"
   ```
2. Create a `spooldir.properties` file with the following contents:
   ```properties
   name=SchemaLessJsonSpoolDir
   tasks.max=1
   connector.class=com.github.jcustenborder.kafka.connect.spooldir.SpoolDirSchemaLessJsonSourceConnector
   input.path=/path/to/data
   input.file.pattern=json-spooldir-source.json
   error.path=/path/to/error
   finished.path=/path/to/finished
   halt.on.error=false
   topic=spooldir-schemaless-json-topic
   value.converter=org.apache.kafka.connect.storage.StringConverter
   ```
3. Load the SpoolDir Schemaless JSON Source connector.
   ```bash
   confluent local load spooldir --config spooldir.properties
   ```

   #### IMPORTANT
   Don’t use the [Confluent CLI](https://docs.confluent.io/confluent-cli/current/index.html) in production environments.

<a id="spooldir-json-source-connector-config"></a>

## Configuration Properties

### General

`topic`
: The Kafka topic to write the data to.
  <br/>
  * Importance: high
  * Type: string

`batch.size`
: The number of records that should be returned with each batch.
  <br/>
  * Importance: low
  * Type: INT
  * Default Value: 1000

`empty.poll.wait.ms`
: The amount of time to wait if a poll returns an empty list of records.
  <br/>
  * Importance: low
  * Type: long
  * Default Value: 500
  * Valid values: [1,…,9223372036854775807]

### Metadata

`metadata.field`
: The name of the field in the value where the metadata will be stored.
  <br/>
  * Importance: low
  * Type: string
  * Default Value: metadata

`metadata.location`
: Location that metadata about the input file will be stored. FIELD - Metadata about the file will be stored in a field in the value of the record. HEADERS - Metadata about the input file will be stored as headers on the record. NONE - no metadata about the input file will be stored.
  <br/>
  * Importance: low
  * Type: string
  * Default Value: HEADERS
  * Valid values: `NONE`, `HEADERS`, `FIELD`

### Auto topic creation

For more information about Auto topic creation, see [Configuring Auto Topic Creation for Source Connectors](/kafka-connectors/self-managed/userguide.html#connect-source-auto-topic-creation).

Configuration properties accept regular expressions (regex) that are defined as
[Java regex](https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html).

`topic.creation.groups`
: A list of group aliases that are used to define per-group topic configurations for matching topics. A `default` group always exists and matches all topics.
  <br/>
  * Type: List of String types
  * Default: empty
  * Possible Values: The values of this property refer to any additional groups. A `default` group is always defined for topic configurations.

`topic.creation.$alias.replication.factor`
: The replication factor for new topics created by the connector. This value must not be larger than the number of brokers in the Kafka cluster. If this value is larger than the number of Kafka brokers, an error occurs when the connector attempts to create a topic. This is a **required property** for the `default` group. This property is optional for any other group defined in `topic.creation.groups`. Other groups use the Kafka broker default value.
  <br/>
  * Type: int
  * Default: n/a
  * Possible Values: `>= 1` for a specific valid value or `-1` to use the Kafka broker’s default value.

`topic.creation.$alias.partitions`
: The number of topic partitions created by this connector. This is a **required property** for the `default` group. This property is optional for any other group defined in `topic.creation.groups`. Other groups use the Kafka broker default value.
  <br/>
  * Type: int
  * Default: n/a
  * Possible Values: `>= 1` for a specific valid value or `-1` to use the Kafka broker’s default value.

`topic.creation.$alias.include`
: A list of strings that represent regular expressions that match topic names. This list is used to include topics with matching values, and apply this group’s specific configuration to the matching topics. `$alias` applies to any group defined in `topic.creation.groups`. This property does not apply to the `default` group.
  <br/>
  * Type: List of String types
  * Default: empty
  * Possible Values: Comma-separated list of exact topic names or regular expressions.

`topic.creation.$alias.exclude`
: A list of strings representing regular expressions that match topic names. This list is used to exclude topics with matching values from getting the group’s specfic configuration. `$alias` applies to any group defined in `topic.creation.groups`. This property does not apply to the `default` group. Note that exclusion rules override any inclusion rules for topics.
  <br/>
  * Type: List of String types
  * Default: empty
  * Possible Values: Comma-separated list of exact topic names or regular expressions.

`topic.creation.$alias.${kafkaTopicSpecificConfigName}`
: Any of the [Changing Broker Configurations Dynamically](/platform/current/kafka/dynamic-config.html#changing-broker-configurations-dynamically) for the version of the Kafka broker where the records will be written. The broker’s topic-level configuration value is used if the configuration is not specified for the rule. `$alias` applies to the `default` group as well as any group defined in `topic.creation.groups`.
  <br/>
  * Type: property values
  * Default: Kafka broker value

### File System

`error.path`
: A directory to place the files that could not be read successfully. This directory must exist and be writable by the user running Kafka Connect.
  <br/>
  * Importance: high
  * Type: string
  * Valid values: Absolute path to a directory that exists and is writable.

`input.file.pattern`
: Regular expression to check input file names against. This expression must match the entire filename. The equivalent of `Matcher.matches()`.
  For valid syntax definitions, see [Class Pattern](https://docs.oracle.com/javase/9/docs/api/java/util/regex/Pattern.html).
  <br/>
  * Importance: high
  * Type: string

`input.path`
: The directory where Kafka Connect reads files that are processed. This directory must exist and be writable by the user running Connect.
  <br/>
  * Importance: high
  * Type: string
  * Valid values: Absolute path to a directory that exists and is writable.

`finished.path`
: The directory where Connect puts files that are successfully processed. This directory must exist and be writable by the user running Connect.
  <br/>
  * Importance: high
  * Type: string

`halt.on.error`
: Sets whether the task halts when it encounters an error or continues to the next file.
  <br/>
  * Importance: high
  * Type: boolean
  * Default Value: true

`cleanup.policy`
: Determines how the connector should cleanup the files that have been successfully processed. DELETE removes the file from the filesystem. MOVE will move the file to a finished directory. MOVEBYDATE will move the file to a finished directory with subdirectories by date.
  <br/>
  * Importance: medium
  * Type: string
  * Default Value: MOVE
  * Valid values: `DELETE`, `MOVE`, `MOVEBYDATE`

`task.partitioner`
: The task partitioner implementation is used when the connector is configured to use more than one task. This is used by each task to identify which files will be processed by that task. This ensures that each file is only assigned to one task.
  <br/>
  * Importance: medium
  * Type: string
  * Default Value: ByName
  * Valid values: `ByName`

`file.buffer.size.bytes`
: The size of buffer for the BufferedInputStream that will be used to interact with the file system.
  <br/>
  * Importance: low
  * Type: INT
  * Default Value: 131072
  * Valid values: [1,…]

`file.minimum.age.ms`
: The amount of time in milliseconds after the file was last written to before the file can be processed.
  <br/>
  * Importance: low
  * Type: long
  * Default Value: 0
  * Valid values: [0,…]

`files.sort.attributes`
: The attributes each file will use to determine the sort order. Name is name of the file. Length is the length of the file preferring larger files first. LastModified is the LastModified attribute of the file preferring older files first.
  <br/>
  * Importance: low
  * Type: list
  * Default Value: [NameAsc]
  * Valid values: `NameAsc`, `NameDesc`, `LengthAsc`, `LengthDesc`, `LastModifiedAsc`, `LastModifiedDesc`

`processing.file.extension`
: Before a file is processed, it is renamed to indicate that it is currently being processed. This setting is appended to the end of the file.
  <br/>
  * Importance: low
  * Type: string
  * Default Value: .PROCESSING
  * Valid values: Matches regex( ^.\*..+$ )

### Schema

`key.schema`
: The schema for the key written to Kafka.
  <br/>
  * Importance: high
  * Type: string

`value.schema`
: The schema for the value written to Kafka.
  <br/>
  * Importance: high
  * Type: string

### Schema Generation

`schema.generation.enabled`
: Flag to determine if schemas should be dynamically generated. If set to true, `key.schema` and `value.schema` can be omitted, but `schema.generation.key.name` and `schema.generation.value.name` must be set.
  <br/>
  * Importance: medium
  * Type: boolean

`schema.generation.key.fields`
: The field(s) to use to build a key schema. This is only used during schema generation.
  <br/>
  * Importance: medium
  * Type: list

`schema.generation.key.name`
: The name of the generated key schema.
  <br/>
  * Importance: medium
  * Type: string
  * Default Value: com.github.jcustenborder.kafka.connect.model.Key

`schema.generation.value.name`
: The name of the generated value schema.
  <br/>
  * Importance: medium
  * Type: string
  * Default Value: com.github.jcustenborder.kafka.connect.model.Value

`timestamp.field`
: The field in the value schema that contains the parsed timestamp for the record. This field cannot be marked as optional and must be a [Timestamp](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Schema.html).
  <br/>
  * Importance: medium
  * Type: string

### Timestamps

`timestamp.mode`
: Determines how the connector sets the timestamp for the [ConnectRecord](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/connector/ConnectRecord.html#timestamp). If set to `Field`, the timestamp is read from a field in the value. This field cannot be optional and must be a [Timestamp](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Schema.html). Specify the field  in `timestamp.field`. If set to `FILE_TIME`, the last time the file was modified is used. If set to `PROCESS_TIME` (the default), the time the record is read is used.
  <br/>
  * Importance: medium
  * Type: string
  * Default Value: PROCESS_TIME
  * Valid values: `FIELD`, `FILE_TIME`, `PROCESS_TIME`

`timestamp.field`
: The field in the value schema that contains the parsed timestamp for the record. This field cannot be marked as optional and must be a [Timestamp](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Schema.html).
  <br/>
  * Importance: medium
  * Type: string

`parser.timestamp.date.formats`
: The date formats that are expected in the file. This is a list of strings that are used to parse the date fields in order. The most accurate date format should be first in the list. See the [Java documentation](https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html) for more information.
  <br/>
  * Importance: low
  * Type: list
  * Default Value: [yyyy-MM-dd’T’HH:mm:ss, yyyy-MM-dd’ ‘HH:mm:ss]

`parser.timestamp.timezone`
: The time zone used for all parsed dates.
  <br/>
  * Importance: low
  * Type: string
  * Default Value: UTC

<!-- WARNING: THIS IS A SHARED FILE AND THE SOURCE IS LOCATED IN DOCS-COMMON. DO NOT ADD TO ANY OTHER REPO. -->

### CSFLE and CSPE configurations

`csfle.enabled`

Accepts a boolean value. CSFLE is enabled for the connector if `csfle.enabled` is set to True.

* Type: boolean
* Default: False

`auto.register.schemas`

Specifies if the Serializer should attempt to register the Schema with Schema Registry.

* Type: boolean
* Default: true
* Importance: medium

`use.latest.version`

Only applies when `auto.register.schemas` is set to false. If `auto.register.schemas` is set to false and `use.latest.version` is set to true, then instead of deriving a schema for the object passed to the client for serialization, Schema Registry uses the latest version of the schema in the subject for serialization.

* Type: boolean
* Default: true
* Importance: medium
