Use cases
Use cases for the JavaScript transform method
A JavaScript transform method can enrich, reshape, and reformat collected JSON data.
Recalculating collected data
Recalculating data involves performing calculations on existing data. Examples include:
Converting units, such as Celsius to Fahrenheit.
Calculating overall equipment efficiency (OEE).
Running trained machine learning algorithms.
Source JSON:
{ "create_ts":"2025-05-06T21:44:51.823Z", "t1":20, "t2":654 }
Recalculated JSON:
{ "temperature_celsius": 20.65, "temperature_fahrenheit": 69.19 }
Enriching collected data
Enhance your data records by adding additional details, such as:
Device names.
Device locations.
Alerts triggered by devices exceeding predefined limits.
Source JSON:
{ "create_ts":"2025-05-06T21:44:51.823Z", "t1":4, "t2":654 }
Enriched JSON:
{ "temperature": 4.65, "alert": "Temperature exceeded 4 degrees Celsius in Freezer 3 in Line 1 Station 2B.", "factory": "Acme Factory 1", "line": "Line 1", "station": "Station 2B", "deviceName": "Freezer 3" }
Reshaping collected data
Reshaping data modifies data structure for consistency and conformance to your company's Unified Namespace. This includes actions like:
Renaming JSON properties.
Nesting properties.
Removing properties.
Adding properties.
Source JSON:
{ "create_ts":"2025-05-06T21:44:51.823Z", "t1":4, "t2":654 }
Reshaped JSON:
{ "dataCollected": "May 6, 2025", "timeCollected": "9:45 PM", "telemetry": [ { "temperatureCelsius": 4.65 } ], "alerts": [ { "alertNumber": 2, "alertMessage": "Temperature exceeded 4 degrees Celsius in Freezer 3 in Line 1 Station 2B.", "alertTimestamp": "2025-05-06T21:44:51.823Z" } ], "deviceInfo": { "factory": "Acme Factory 1", "line": "1", "station": "Station 2B", "deviceName": "Freezer 3" }, "sourceData": { "create_ts":"2025-05-06T21:44:51.823Z", "t1":4, "t2":654 } }
Reformatting collected data
A JavaScript transform method can reformat JSON data into another format, such as an operator-friendly alert message.
Reformat data by converting the output to any data format, such as comma-separated values or descriptive text. For example, you can take JSON, determine if its values exceed thresholds, and replace the JSON with an operator-friendly alert message.
Reformatting data modifies the format of data for particular software. This includes action like:
Converting JSON into user-friendly sentences.
Converting JSON into CSV, which is compatible with spreadsheet software.
Converting JSON into XML.
Converting a JPEG image into PNG.
Source JSON:
{ "temperature": 4.65, "pressure": 14.696 }
Reformatted as human-readable text:
Temperature is 5 degrees Celsius and air pressure is 15 psi.
Reformatted as XML:
<?xml version="1.0" encoding="UTF-8" ?> <root> <temperature>4.65</temperature> <pressure>4.65</pressure> </root>
Reformatted as CSV:
temperature,pressure 4.65,14.696