target Attribute¶
The target
attribute within the generate
and execute
element in DATAMIMIC allows users to specify the desired output format for the generated data. This functionality provides flexibility in directing the output to different formats or environments, whether built-in options like CSV or custom configurations like databases.
Built-in Supported Targets¶
DATAMIMIC natively supports the following output targets:
Preview
: Default value, data generated will always get output with a limited subset to ourDATAMIMIC UI Preview
.LogExporter
: Prints the data in theLog View
. This exporter it mostly used for debug purpose, so it has a default max limit of 100 items. We recommend to use our other exporters such as CSV, TXT... if you were to handle larger dataset.ConsoleExporter
: Prints the generated data directly to the console, useful for quick debugging and verification.mem
: Outputs the data to an in-memory store, allowing for quick access and manipulation within the same environment.CSV
: Exports the generated data to a CSV file, which is ideal for handling tabular data and can be easily imported into spreadsheet applications. This file can be downloaded from our DATAMIMIC UI Artifact.JSON
: Outputs the data in JSON format, suitable for web applications and data interchange between systems. This file can be downloaded from our DATAMIMIC UI Artifact.JSONSingle
: Outputs the data in JSON format, but with each record in a single file. This file can be downloaded from our DATAMIMIC UI Artifact.OpenSearchBulk
: Exports the data in OpenSearch bulk format, which is useful for bulk indexing data into OpenSearch. This file can be downloaded from our DATAMIMIC UI Artifact.TXT
: Saves the data as a plain text file, suitable for simple text-based records or logs. This file can be downloaded from our DATAMIMIC UI Artifact.XML
: Exports the data to an XML file, useful for structured data storage and data exchange between different systems. This file can be downloaded from our DATAMIMIC UI Artifact.

Notes
The target
attribute supports multiple values, allowing you to combine different output formats or environments. This can be particularly useful when you want to direct the same generated data to multiple locations simultaneously.
Example Usage with Built-in Targets¶
Here’s an example of how to use the <generate/>
element with a built-in target:
1 2 3 4 5 6 |
|
Custom Environment Targets¶
DATAMIMIC also supports custom environments, allowing users to direct output to specific databases, message brokers, or other external systems. For example:
- Databases: Write generated data directly into a database.
- Kafka: Send generated data to a Kafka topic.
- MongoDB: Insert generated data into a MongoDB collection.
To use a custom environment as a target, we must first create the Environment from our DATAMIMIC UI, and then specify it in the target attribute:
1 2 3 4 5 |
|
Check out our Database Tutorial for a more detail example usage.
Example Usage and configuration of supported targets¶
CSV¶
1 2 3 4 |
|
we also can specify the CSV file configuration such as delimiter
, quotechar
, quoting
, encoding
, line_terminator
and chunk_size
:
1 2 3 4 |
|
JSON / JSONSingle¶
We can generate JSON files with multiple records in a single file or each record in a separate file by define the target as JSON
or JSONSingle
:
JSONSingle is actually a special case of JSON, where each record is saved in a separate file. The records are not saved in an array, but as individual JSON files.
The same is happening when we use the JSON(chunk_size=1) target.
1 2 3 4 |
|
We can also specify the JSON file configuration such as use_ndjson
, encoding
and chunk_size
:
1 2 3 4 |
|
OpenSearchBulk¶
The OpenSearchBulk target is used to generate data in the OpenSearch bulk format. This format is used to bulk index data into OpenSearch. The generated data is saved in a file with the extension .json
or .ndjson
and can be imported into OpenSearch using the bulk API.
The default configuration for the OpenSearchBulk target is as follows chunk_size=None, encoding='utf-8', use_ndjson=True: This means no chunking, utf-8 encoding, and using NDJSON format.
1 2 3 4 |
|
when we set use_ndjson=False, the generated data will be saved in a JSON format and stored in an array:
1 2 3 4 5 6 |
|
To use the OpenSearchBulk target, we can define the target as OpenSearchBulk
and the model needs to specify the keys for the index, id, and routing:
$$_action$$
: The action to perform on the document, such as index, create, or delete.
$$_index$
$: The index to which the document belongs.
$$_id$$
: The unique identifier for the document.
$$routing$$
: The routing value for the document.
Here is an example of how to use the OpenSearchBulk target:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
here is the content of the script/template_xyz.json
file:
1 2 3 4 5 6 |
|
the output will be saved in a file with the extension .json
and can be downloaded from our DATAMIMIC UI Artifact.
Preview of the generated data in the OpenSearchBulk format:
1 2 3 4 5 6 7 8 |
|