Overview
Digital twins are decoupled from physical devices. You can use data mapping to map raw data from physical devices to the business models of digital twins. The data is mapped to the properties of the Thing Specification Language (TSL) model on the digital twin nodes. This topic describes the concepts of data mapping configuration.
Usage notes
Data mapping consists of the following three parts:
Configuration item | Description |
Data source type | Data source types include the following:
|
Script file | Use JavaScript to write a script that parses and processes data from the configured data source, and then outputs data in JSON format. The file size cannot exceed 128 KB. |
Output file | Use the specified JSON data format to map data from the data source, or data processed by the script, to the TSL model properties of a specified digital twin node. The file size cannot exceed 256 KB. |
For more information about how to edit script files and output files, see Script and output syntax.
Scenarios
Data mapping is used in the following scenarios:
If the data source is a TSL model property topic, you can complete the data mapping using an output file. A script file is not required. The following figure shows this process.

If the data source is a custom topic or the data is from an API and is in JSON format, you can complete the data mapping using an output file. A script file is not required. The following figure shows this process.

If the data source is a custom topic, you must first use a script file to parse and process the data. Then, you can use an output file to complete the data mapping. The following figure shows this process.

If the data source is data parsed in DataService Studio, a data parsing task can perform complex processing and calculations on raw device data. For more information, see Data parsing. To process and calculate the raw device data, you can first transfer the device data to a data analytics task for more complex processing. Then, set the destination node for data parsing to IoT Digital Twin and use an output file to complete the data mapping. The following figure shows this process.
ImportantIn the output data format for data parsing, payload and ts are system fields. The payload field represents the data output from the parsing process. The ts field represents the processing timestamp in UTC and is measured in milliseconds.
If the data source is data from a custom storage table in DataService Studio, a script file and an output file are not required. The value of the value field is directly mapped to the TSL model property of the corresponding digital twin node based on the values of the iotId and identifier fields.
ImportantThe data type for data mapped from a custom storage table in DataService Studio to the IoT Digital Twin Engine is always String. The IoT Digital Twin Engine converts the string to the property type of the corresponding digital twin node. If the conversion fails, the operation is skipped.
How to configure data mapping