Publish an Object Hierarchy to an MQTT Topic Hierarchy
Building Dynamic MQTT Topic Paths in an Intelligence Hub Pipeline
What Does This Article Cover:
This article shows three ways to publish an object hierarchy to MQTT using a single pipeline example. The example pipeline is named demo_objecthierarchy and begins with a JavaScript stage that creates a payload containing site, area, line, asset, and a nested values object. The pipeline then branches into three different MQTT write patterns.
Example object used in this article
{
"site": "Portland",
"area": "Area1",
"line": "Line1",
"asset": "Motor01",
"values": {
"amps": 12.4,
"speed": 1775,
"vibration": 0.08
}
}
Method 1: Using a predefined MQTT output with a WriteNew stage
What this method is doing
The first branch uses a Write stage that is called WriteOldSchool with a target referencing the predefined MQTT output.
Why this method
This is considered the simplest version to use, and rather than a technical example, it is the best conceptual explanation since the pipeline stage uses the incoming object and points it to the existing output. This really allows you to see how simple it is to configure the MQTT behavior in the output object and then reuse that output from the pipeline. However, it is important to note that this is a predefined MQTT output.

Method 2: Using a WriteNew stage to build the topic directly in the stage
What this method is doing
The second branch is using a WriteNew stage with a topic that is built in directly from topic that is built in from the object hierarchy using this topic branch:
////write_new
and its template is:
${value.values}
The template is going to configure the publish payload with the nested values object while using the hierarchy fields to build the MQTT topic.
What this teaches the user
This method shows that the hierarchy does not need to be only in the payload. It can also be used in the MQTT topic path. In this example, site, area, line, and assets are used for the topic, while the values are used for the payload.
Why this method
This method takes the hierarchy fields and puts them into the MQTT topic, then sends only the values object as the payload. This is considered a new style because everything now becomes visible in the platform.

Method 3: Building the topic and the payload first, then write using metadata
What this method is doing
The third branch is the most step-by-step and uses three stages.
- BuildTopicPath
- PreppingMQTT
- WriteNew
In the BuildTopicPath, a JSONata transform creates a new object with two fields:
- topicPath
- payload

Then the payload itself just has amps, speed, and vibration. After this stage, the topic path should be stored in metadata, and the payload becomes only the measurement object. Then, in the last stage, WriteNew publishes the transformed payload.
Why teach this method:
This is the best teaching example if the goal is to learn because it shows the reader that you can prepare the MQTT topic and payload before the write stage instead of doing everything inside the write stage itself.