# Handling a JSON list of metrics in MQTT

**URL:** <https://forum.inductiveautomation.com/t/handling-a-json-list-of-metrics-in-mqtt/99266>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [November 29, 2024, 3:50pm UTC](https://forum.inductiveautomation.com/t/handling-a-json-list-of-metrics-in-mqtt/99266 "2024-11-29T15:50:32Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 7, 2025, 6:08pm UTC](https://forum.inductiveautomation.com/t/handling-a-json-list-of-metrics-in-mqtt/99266/19 "2025-04-07T18:08:02Z")

</div>

> [@Jani\_Kleindienst1](#):
>
> more information about this?

Probably should read this whole topic to get a feel for what it can do:

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934):
>
> Automation Professionals is pleased to announce the immediately availability of a major upgrade to its free Simulation Aids Integration Toolkit module. The new feature justifying the "major upgrade" language is the implementation of eleven thirty-one new expression functions which use iteration to accomplish complex transforms of datasets and lists, to or from other datasets and lists, applying filtering, ordering, and computed new columns along the way. While there are certain operations that…

> [@Jani\_Kleindienst1](#):
>
> Can I map the JSON from MQTT to a Tag of type Document or Dataset?

Either. Given your format, I'd recommend a dataset, with dedicated columns for the possible datatypes. (Similar to IA's historian tables.)

Probably something like this in an expression tag (event triggered):

```python
transform(
	jsonDecode({path/to/source/jsonAsString}),
	transform(
		doDate(value()['eventTime'],
		unionAll(
			asMap(
				'machineId', 'str',
				't_stamp', 'date',
				'varName', 'str',
				'varUnit', 'str',
				'boolValue', 'B',
				'longValue', 'L',
				'doubleValue', 'D'
			),
			forEach(
				value(1)['data'],
				value(1)['machineId'], // All rows get this ID
				value(), // All rows get the parsed event time
				it()['name'],
				it()['measurementUnit'],
				if(
					it()['dataType'] = 'boolean',
					toBoolean(it()['value']),
					null
				),
				if(
					it()['dataType'] = 'int' || it()['dataType'] = 'long',
					toLong(it()['value']),
					null
				),
				if(
					it()['dataType'] = 'float' || it()['dataType'] = 'double',
					toDouble(it()['value']),
					null
				)
			)
		)
	)
)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/handling-a-json-list-of-metrics-in-mqtt/99266)._
