IMD SolutionComputing LibraryShop main store

How-to

Publish raw JSON from Ignition Document tags via MQTT Transmission

Edge computing and IIoT Published 8 min read By IMD Solution engineering team

Short answer

Neither MQTT Transmission transmitter can emit a Document tag as the raw MQTT body: the UNS Transmitter escapes it as a String inside its JSON envelope, and the Sparkplug Transmitter carries it as a String metric inside Protobuf. The supported route on Ignition 8.3 is the module's publish API — your script serializes the document once, publishes it to the agreed topic, and a one-pass subscriber parse proves the body is raw.

On this page
  1. Why does the Document tag arrive at the consumer wrapped?
  2. Is there a supported way to publish the raw JSON from Ignition?
  3. How do I serialize and publish the Document tag without double-wrapping?
  4. What must the subscriber capture prove about the body?
  5. What does one Document publish cost against atomic Sparkplug metrics?
  6. Which publish path do I commit to for each consumer?
  7. Questions asked

No setting on either MQTT Transmission transmitter delivers an Ignition Document tag to the broker as the raw JSON you built. The UNS Transmitter maps the Document to a String and escapes it inside its own JSON envelope; the Sparkplug Transmitter carries that String as a metric inside a binary Protobuf payload. The supported route is the module's publish API: your script serializes the document once and publishes the bytes itself. This article gives that path, the subscriber capture that proves the body is raw, and the decision between one document and atomic Sparkplug metrics.

Why does the Document tag arrive at the consumer wrapped? #

Both transmitters re-encode the tag: the UNS Transmitter maps the Document value to a String and escapes it inside its own JSON envelope, while the Sparkplug Transmitter places that String in a metric inside a Protobuf binary payload. Follow one value from tag to wire and the wrapping point is the transmitter, not the tag. A Document tag holds a parsed document; each transmitter then applies the encoding its own consumers expect. The UNS Transmitter publishes a JSON structure of its own with your document as an escaped String member, so the consumer parses the envelope and then parses your text a second time. The Sparkplug Transmitter encodes everything into the binary payload defined by Sparkplug's Protobuf definition, and that definition admits nothing outside itself — your JSON can only ride as a String metric. A generic MQTT client subscribed to that topic shows unreadable bytes, which is the binary format working as designed, as covered in why Ignition Edge MQTT payloads look like unreadable bytes.

Publish path Wire representation Consumer work Raw JSON body?
UNS Transmitter JSON envelope with the document escaped as a String Parse the envelope, extract the String, parse it again as JSON No
Sparkplug Transmitter Protobuf binary payload with the document as a String metric Decode the Protobuf, locate the metric, parse its String as JSON No
MQTT Transmission publish API The payload your script supplies Parse the body once as JSON Yes, when you supply serialized JSON

No configuration option on either transmitter turns its encoder into a transparent pass-through; the encoding is the contract each transmitter offers its consumers.

Is there a supported way to publish the raw JSON from Ignition? #

Yes: the publish API documented for the MQTT Transmission module on Ignition 8.3, which hands the MQTT payload to your script instead of routing the tag through a transmitter encoder. MQTT Transmission belongs to the 8.3 IIoT architecture, where MQTT's publish/subscribe model moves data between plant and IT systems; the IIoT architecture chapter of the Ignition user manual describes that layout.

On that model the publish API makes your script the publisher: it reads the tag, serializes the document, chooses the topic, and submits the payload bytes. Open the module's publishing documentation for your installed 8.3 module version and use the function name and payload type that page shows; the signature is specific to the module version, so take it from there rather than from an example written against another release. This route is the only one of the three that returns your JSON as the body itself. Sparkplug cannot carry an arbitrary JSON body outside its Protobuf definition — correct behavior when the receiving system is a Sparkplug endpoint, and the wrong contract when IT's consumer expects to parse the MQTT body directly.

How do I serialize and publish the Document tag without double-wrapping? #

Serialize the document exactly once and let the API publish that text: read the tag, check its quality, pass the value through the platform JSON encoder, and submit the result as the payload — never stringify first and encode that String again.

  1. Read the Document tag, for example at Enterprise/Site/M6/F6A/R-21130/Equipment/Parameters/Temperature/Measurement/Sensor 1, and reject the publish when the quality is not good: a bad-quality document published as a normal update reads as live data downstream.
  2. Pass the document value through the platform JSON encoder one time. The tag already holds a parsed document, so a single encode produces the JSON text; converting the value to a String first and encoding that String is what produces the double-wrapped form you are leaving behind.
  3. Validate the serialized text in a test: parse it once and confirm the root is a single JSON object whose members include template, messageType, metadata, and data.
  4. Publish through the function the module documentation names for your installed 8.3 module version, to the topic agreed with IT, at a QoS that matches the update rate.
  5. Capture the message at a test subscriber before the production consumer sees it, and file the capture with the commissioning record.

The body that arrives should be the document itself, as in this example from one sensor tag:

{
  "template": "PI_Value_update",
  "messageType": "add",
  "globalTimeStamp": "2026-03-04T16:06:45Z",
  "messageID": "dd21081f-ea44-4146-819e-f0a30c1e4bd6",
  "version": "1.1.0",
  "metadata": {
    "DataGroup": "PI Data",
    "Alias": null,
    "DefaultUOM": "UOM",
    "DataType": "Integer",
    "UNSPath": "Enterprise/Site/M6/F6A/R-21130/Equipment/Parameters/Temperature/Measurement/Sensor 1"
  },
  "data": [
    {
      "uom": "",
      "dataQuality": "Good",
      "questionable": false,
      "substituted": false,
      "source": "SINUSOID",
      "value": "25.1700172",
      "annotated": false,
      "timestamp": "2026-03-04T16:00:27Z",
      "dataValidation": {
        "result": "Failed",
        "reason": ["Missing mandatory field(s): uom"]
      }
    },
    {
      "uom": "",
      "dataQuality": "Good",
      "questionable": false,
      "substituted": false,
      "source": "SINUSOID",
      "value": 26.3145771,
      "annotated": false,
      "timestamp": "2026-03-04T16:03:27Z",
      "dataValidation": {
        "result": "Failed",
        "reason": ["Missing mandatory field(s): uom"]
      }
    }
  ]
}

Preserving structure is not the same as preserving characters. A document re-serialized from the parsed tag value keeps every member and type, but whitespace, member order, and numeric formatting are not guaranteed to match the original file. If the consumer's contract is byte-for-byte identity, publish the original text the source system produced — kept in a String tag or file — rather than a re-serialization.

What must the subscriber capture prove about the body? #

The capture must parse in one pass as a single JSON object with template, messageType, metadata, and data at the root; if the consumer parses twice, the document left Ignition as a String inside something else. Beyond the root check, confirm that the types survived the single pass — the example document carries a mix worth testing deliberately:

Member in the example Representation on the wire Decision
metadata.Alias JSON null Confirm the consumer accepts null, or have the source omit the member
first data entry value JSON String "25.1700172" Normalize to a number if the receiving schema requires numeric typing
second data entry value JSON number 26.3145771 Make the typing consistent across samples, one way or the other

A value that reaches an analog point as a quoted string fails that point, so settle the String-versus-number question before the consumer is built; the failure is described in why a quoted MQTT JSON value fails an analog point.

What does one Document publish cost against atomic Sparkplug metrics? #

One document pays MQTT's per-message overhead once per update, while atomic values as Sparkplug metrics can share one Protobuf payload, so the choice turns on the consumer's contract more than on raw broker throughput. Size the per-message cost with example inputs — a serialized document of 800 bytes, a topic of 58 bytes, a QoS 0 publish under MQTT 3.1.1 — and measure your own serialized size before quoting numbers to IT.

The variable header of a QoS 0 publish is the 2-byte topic length plus the topic. The remaining length is 2 + 58 + 800 = 860 bytes, and any remaining length from 128 to 16383 takes a 2-byte remaining-length field, so the fixed header is 1 type byte plus 2 length bytes. The frame is 3 + 2 + 58 + 800 = 863 bytes, of which 63 bytes — about 7.3 percent — is overhead. Publish the same update as 20 separate messages of 45 bytes each on the same topic and each remaining length is 2 + 58 + 45 = 105 bytes, under 128, so the fixed header is 2 bytes and each frame is 2 + 2 + 58 + 45 = 107 bytes. Twenty frames total 2140 bytes, of which 20 × 62 = 1240 bytes — about 58 percent — is overhead, roughly 2.5 times the bytes of the single-document route.

Sparkplug's answer to that arithmetic is batching, not smaller messages: many metrics ride one Protobuf payload, including the same data point under different timestamps, and the binary encoding is typically more compact than the equivalent JSON. What batching cannot do is preserve your document — each metric keeps its own value, quality, and timestamp inside the Sparkplug model, and the pre-built JSON structure is gone.

Design Broker and message effect Consumer effect
One raw Document publish One message per update; overhead paid once; any change republishes the whole document One JSON parse, then schema validation
Atomic Sparkplug metrics Many metrics per Protobuf payload; compact binary; per-value timestamps and quality retained Efficient binary decode into defined metrics
JSON inside a Sparkplug String metric Protobuf carries the JSON text plus metric metadata Protobuf decode, then a JSON parse; the document stays opaque to Sparkplug

Which publish path do I commit to for each consumer? #

Commit to the publish API when IT's contract is "the MQTT body is the JSON document", to the Sparkplug Transmitter when the consumer wants typed metrics with value, quality, and timestamp, and to the UNS Transmitter only when the consumer already parses that envelope.

  • The MQTT body must be the document: publish API, one serialization, one-pass parse at the consumer, capture filed as proof.
  • The consumer is a Sparkplug-aware endpoint: Sparkplug Transmitter with atomic tags, many metrics per payload, per-value quality and timestamps intact.
  • The consumer is already built against the UNS envelope: keep the UNS Transmitter and accept the second parse as part of that contract.

Whichever you choose, the commissioning test is the same: subscribe, parse once, and check the root members and their types against the agreed schema.

Questions asked

Does Sparkplug B have a metric type that holds a nested JSON object?

No. The Protobuf definition fixes the metric types (booleans, integers, floats, strings, datetimes, bytes, datasets and the like), and none of them is an arbitrary object. A JSON document can only ride as a String metric, so Sparkplug-aware consumers see opaque text, not your structure. That is a limit of the specification, not a configuration gap in the transmitter.

What does QoS 1 add to each raw publish?

Under MQTT 3.1.1, QoS 1 puts a 2-byte packet identifier in each publish and the broker answers with a 4-byte PUBACK, so the sender knows the message arrived. Use QoS 1 when a lost update is not corrected by the next one, such as an alarm-state document; stay on QoS 0 when each update supersedes the previous one and a gap is harmless.

Can several sensor documents go out in one publish?

Yes, if IT accepts a JSON array instead of one object per message: serialize the documents, publish them as one array, and the per-message overhead is paid once for the batch. That changes the schema the consumer validates, so agree the array contract before building it, and adjust the one-pass root check to expect an array.

Is the failed uom validation in the example payload a transmission fault?

No. The document itself carries dataValidation result Failed with the reason Missing mandatory field(s): uom, so the source system flagged the value before Ignition ever saw it, and the transport delivered the flag faithfully. Correct the unit at the source, or let the consumer honor the flag; no MQTT or transmitter setting changes it.

Keep reading

  • Explainer

    Shrinking a Sparkplug JSON payload on a narrow link

    Casting the JSON to bytes changes the Sparkplug datatype tag, not the size: String and Bytes metrics both ride one protobuf length-delimited field with the same length prefix. The example's ~700-byte object minifies to ~400 bytes and shrinks further as typed metrics with aliases; with a 1460-byte IPv4 segment limit, the gain is bytes on the link, not packets.

    Edge computing and IIoT

  • Troubleshooting

    Why a Sparkplug integer array is missing in MQTT.fx

    The array is almost certainly on the wire: MQTT Transmission and MQTT Engine support Integer Arrays from version 4.0.6, while the MQTT.fx parser does not decode Sparkplug arrays. Verify the payload in the MQTT Engine tag provider on the same MQTT server, and treat MQTT.fx as a wiring check only.

    Edge computing and IIoT

  • Troubleshooting

    Why an MQTT tag path bracket shows all array values

    The MQTT tag holds the whole JSON payload as one string, so a bracketed path suffix cannot select an element. Remove the bracket, add an expression transform that parses the string with jsonGet, and request index 1 for the second element, because JSON array indexes are zero-based.

    Edge computing and IIoT

OpenEMS InfluxDB password versus API token in Docker