# Reformat json and remove array structure

**URL:** <https://discourse.nodered.org/t/reformat-json-and-remove-array-structure/72237>\
**Category:** General\
**Tags:** function-node\
**Created:** [15 December 2022 07:13 UTC](https://discourse.nodered.org/t/reformat-json-and-remove-array-structure/72237 "2022-12-15T07:13:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![th0maz](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@th0maz](https://discourse.nodered.org/u/th0maz)\
**Post date:** [15 December 2022 07:13 UTC](https://discourse.nodered.org/t/reformat-json-and-remove-array-structure/72237/1 "2022-12-15T07:13:38Z")

</div>

Hi, I need some help with this.  
My Shelly 3EM with Tasmota sends status messages like this:

```auto
{
	"Time": "2022-12-14T17:40:07",
	"ENERGY": {
		"Value1": 11,
		"Value2": 12,
		"Value3": 13,
		"Power": [
			1693,
			168,
			14
		],
		"Frequency": [
			50,
			50,
			50
		],
		"Voltage": [
			234,
			234,
			237
		],
		"Value4": 14
	}
}

```

I would like to send this to an InfluxDB and for this to remove the arrays. I think I need something like this:

```auto
	"ENERGY": {
		"Value1": 11,
		"Value2": 12,
		"Value3": 13,
		"Power_A": 1693,
		"Power_B": 168,
		"Power_C": 14,
		"Frequency_A": 50,
		"Frequency_B": 50,
		"Frequency_C": 50,
		"Voltage_A": 234,
		"Voltage_B": 234,
		"Voltage_C": 237,
		"Value4": 14
	}

```

How can this be done?  
Thanks!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [15 December 2022 07:46 UTC](https://discourse.nodered.org/t/reformat-json-and-remove-array-structure/72237/2 "2022-12-15T07:46:01Z")

</div>

The simplest option would be to run it through a template node to format the output  
e.g.

```auto
[{"id":"8af8b10a92587694","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \t\"Time\": \"2022-12-14T17:40:07\", \t\"ENERGY\": { \t\t\"Value1\": 11, \t\t\"Value2\": 12, \t\t\"Value3\": 13, \t\t\"Power\": [\t\t\t1693, \t\t\t168, \t\t\t14 \t\t], \t\t\"Frequency\": [\t\t\t50, \t\t\t50, \t\t\t50 \t\t], \t\t\"Voltage\": [\t\t\t234, \t\t\t234, \t\t\t237 \t\t], \t\t\"Value4\": 14 \t} }","payloadType":"json","x":330,"y":340,"wires":[["6b6a0f9a71d9a31b"]]},{"id":"6b6a0f9a71d9a31b","type":"template","z":"da8a6ef0b3c9a5c8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n\t\"ENERGY\": {\n\t\t\"Value1\": {{payload.ENERGY.Value1}},\n\t\t\"Value2\": {{payload.ENERGY.Value2}},\n\t\t\"Value3\": {{payload.ENERGY.Value3}},\n\t\t\"Power_A\": {{payload.ENERGY.Power.0}},\n\t\t\"Power_B\": {{payload.ENERGY.Power.1}},\n\t\t\"Power_C\": {{payload.ENERGY.Power.2}},\n\t\t\"Frequency_A\": {{payload.ENERGY.Frequency.0}},\n\t\t\"Frequency_B\": {{payload.ENERGY.Frequency.1}},\n\t\t\"Frequency_C\": {{payload.ENERGY.Frequency.2}},\n\t\t\"Voltage_A\": {{payload.ENERGY.Voltage.0}},\n\t\t\"Voltage_B\": {{payload.ENERGY.Voltage.1}},\n\t\t\"Voltage_C\": {{payload.ENERGY.Voltage.2}},\n\t\t\"Value4\": {{payload.ENERGY.Value4}}\n\t}\n}","output":"json","x":520,"y":340,"wires":[["e5e60a2f2d3ff4cc"]]},{"id":"e5e60a2f2d3ff4cc","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 114","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":380,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![th0maz](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@th0maz](https://discourse.nodered.org/u/th0maz)\
**Post date:** [15 December 2022 08:33 UTC](https://discourse.nodered.org/t/reformat-json-and-remove-array-structure/72237/3 "2022-12-15T08:33:23Z")

</div>

That did the trick, thank you.  
I wasn't aware of the template node 👌

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 December 2022 08:33 UTC](https://discourse.nodered.org/t/reformat-json-and-remove-array-structure/72237/4 "2022-12-29T08:33:28Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
