Configure transformations
9 min
a transformation converts the raw json data on a topic into a format that northbound systems can consume you define a transformation as a schema in a litmus edge (le) model, apply it to a dynamic attribute, and the transformed result replaces the raw data in the instance payload this topic shows you how to add a transformation schema, test it, and apply it to a dynamic attribute for the rest of the model, see create and configure a model docid\ zpadx1lmme0f44v7r6v6q note also see digital twins docid\ xlj3gvozyg 52ue4pb5u7 for overview and background information before you begin before you configure a transformation, make sure you have a model with at least one dynamic attribute sample data from the topic that feeds the attribute so you can test the schema in the playground json or jsonata schema type what it does use it for json filters the payload to a specific set of key value pairs stripping unwanted fields from a data source jsonata applies conditional logic, computed values, and dynamic filtering alerts, computed outputs, or reformatting timestamps jsonata schemas use the jsonata https //docs jsonata org/overview\ html query language add a transformation schema to define a schema in the model click the transformation tab, then click add a schema enter a name for the schema from the schema type drop down menu, select json or jsonata in the code window, paste the json or jsonata schema optionally, select system variables from the code drawer to insert them into the schema see system variables docid\ tbkp rlu3ocbdjcnjy4lq test the schema in the playground a schema that returns the wrong shape reaches every instance payload built from the model test it in the playground before you apply it to an attribute to test the schema in the playground, enter sample data from the topic that feeds the attribute the playground displays the transformed output compare the transformed output with the output you expect adjust the schema until the output matches click add the schema appears in the transformation tab apply the schema to a dynamic attribute a schema takes effect only on the attributes that reference it you can apply the same schema to more than one dynamic attribute to apply the schema click the dynamic attributes tab select the dynamic attribute you want to transform in the schemaid field, select the schema click save model to edit or delete a schema, click the action menu for the schema in the transformation tab and select edit or remove system variables use system variables to add model and instance context to a transformed payload select them from the code drawer in the schema editor variable inserts {edge dt system time} the device system time when the payload is published {edge dt model version} the version of the model the instance was created from {edge dt model name} the name of the model the instance was created from {edge dt model id} the unique identifier of the model {edge dt instance id} the unique identifier of the instance verify the transformation works note an instance runs against the model version it was created from click upgrade instances on the model to apply a new or changed schema to an existing instance to confirm the transformation is applied navigate to digital twins > instances select an instance created from the model click the data access tab subscribe to the instance topic the data access tab displays the assembled payload confirm that the dynamic attribute shows the transformed shape rather than the raw data related topics digital twins docid\ xlj3gvozyg 52ue4pb5u7 create and configure a model docid\ zpadx1lmme0f44v7r6v6q configure parameters docid\ tsncjwvos5h4bxmoujicg add an instance docid\ jzoth4t0hcrtrauusdryk model and instance actions docid\ hk0idxlg7zcoetajwcobo