# Array within Device Tag

**URL:** <https://forums.losant.com/t/array-within-device-tag/4634>\
**Category:** Help\
**Tags:** tags, device\
**Created:** [July 11, 2022, 11:35am UTC](https://forums.losant.com/t/array-within-device-tag/4634 "2022-07-11T11:35:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisGM](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@ChrisGM](https://forums.losant.com/u/ChrisGM)\
**Post date:** [July 11, 2022, 11:35am UTC](https://forums.losant.com/t/array-within-device-tag/4634/1 "2022-07-11T11:35:06Z")

</div>

Hi,

I’ve hit 100 tags for a particular device application. (Storing various thresholds and labelling fields).

Storing these in a small array could reduce my tag count by 75% if this works, however I can’t seem to get my syntax correct.

If I store a tag called:  
D2\_TEST  
With a value of:  
{“key”: “foo”, “value”: “bar”}

Can I reference this address in a Gauge label for example?

I can read in a single char:  
{{ ctx.deviceId-0.tags.D2\_TEST.[0].[0] }}

However I can’t seem to address:  
{{ ctx.deviceId-0.tags.D2\_TEST.key }} for example

Hopefully it’s a minor formatting error!

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [July 11, 2022, 1:15pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/2 "2022-07-11T13:15:10Z")

</div>

The issue is that, though your value resembles an object, it is still being treated as a string. I wrestled with this for a while but I cannot figure out a way using our Handlebars rendering engine to cast that value to an object, which would allow you to then look up the properties within it. I’m going to file a feature request for a new Handlebars helper that would allow for this use case (casting a stringified object to an actual object).

As a side note, would moving any of these device tags to [attribute tags](https://docs.losant.com/devices/attributes/#including-optional-fields) solve your use case? Those values are also available on the device context object just like device tags are.

---

<div class="post-metadata">

**Author:** ![ChrisGM](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@ChrisGM](https://forums.losant.com/u/ChrisGM)\
**Post date:** [July 12, 2022, 3:39pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/3 "2022-07-12T15:39:09Z")

</div>

Most of them would be better stored as attribute tags for sure. Many are attribute specific.

However they do need to be updated by the user, using a input control form on a dashboard. When I started playing with the workflow I realised I couldn’t use the Device Update node to set these Attribute Tags.

I found a forum post referencing the API, but apparently needing to update ‘all’ tags in one hit, every time, which I thought best to avoid. Proceeded to use Device Tags, and found a limit of 100 tags.

If I’m mistaken above on the attribute tags, that would be a great result! Any ideas would be appreciated.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [July 12, 2022, 4:10pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/4 "2022-07-12T16:10:40Z")

</div>

You’re right about the [Device: Update Node](https://docs.losant.com/workflows/data/update-device/) not allowing the setting of attribute tags, and also about the [Device: Patch API endpoint](https://docs.losant.com/rest-api/device/#patch) requiring the passing of the entire attributes array when adding, removing, or editing any attribute.

One workaround I’ve used in the past is to use the [Devices: Patch API endpoint](https://docs.losant.com/rest-api/devices/#patch) (also known as the “Bulk Device Update endpoint”) to update a single attribute tag, as that endpoint does support such an operation. So you’d build your device query to only target a single device, and then using the “Attribute Tag: Set” operation to change the value of all (one) devices matching the query.

That endpoint is pretty confusing, so I’ve attached a starter workflow you can use. You’ll probably need to change the variable names to match what you’re passing from your Input Controls Block but other than that, this should allow users to safely set individual device attribute tag values.

[set-attribute-tag-develop.flow](https://forums.losant.com/uploads/short-url/hR01mRwEB5dZNGhk71DteVxXez0.flow) (3.3 KB)

---

<div class="post-metadata">

**Author:** ![ChrisGM](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@ChrisGM](https://forums.losant.com/u/ChrisGM)\
**Post date:** [July 12, 2022, 4:12pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/5 "2022-07-12T16:12:54Z")

</div>

Thanks Dylan,  
That sounds like a good solution, I’ll give it a try.

---

<div class="post-metadata">

**Author:** ![ChrisGM](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@ChrisGM](https://forums.losant.com/u/ChrisGM)\
**Post date:** [July 14, 2022, 3:13pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/6 "2022-07-14T15:13:27Z")

</div>

Hi @Dylan_Schuster,

This is working well for a single attribute tag update.

Could this schema be used to update a batch of say 3 or 4 tags in one go?

Many thanks,

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [July 14, 2022, 3:56pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/7 "2022-07-14T15:56:04Z")

</div>

Absolutely; you can just add additional instruction objects to the `updateOperations` array. For example, copy, the highlighted operation in this screenshot and make the necessary adjustments to target a different attribute / attribute tag.

Note that if you want to target different devices per operation, that is something that will require a separate API call.

 ![Screen Shot 2022-07-14 at 11.54.20 AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/2/222994ea29fbc742fac00d23ad081f1d3a1de5a2.png)

---

<div class="post-metadata">

**Author:** ![Sebastian\_Turner](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/sebastian_turner/32/4024_2.png) [@Sebastian\_Turner](https://forums.losant.com/u/Sebastian_Turner)\
**Post date:** [December 1, 2022, 4:05pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/8 "2022-12-01T16:05:31Z")

</div>

Following up on this thread. The feature request that @Dylan_Schuster [referenced above](https://forums.losant.com/t/array-within-device-tag/4634/2) has been released.

`{{jsonDecode val}}` treats `val` as a JSON string and parses it, thereby casting that value to an actual object. While the workflow solution that Dylan shared above is still valid, use of this helper simplifies this process.

---

<div class="post-metadata">

**Author:** ![Chris\_GM](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@Chris\_GM](https://forums.losant.com/u/Chris_GM)\
**Post date:** [March 5, 2023, 10:24am UTC](https://forums.losant.com/t/array-within-device-tag/4634/9 "2023-03-05T10:24:55Z")

</div>

Hi @Sebastian_Turner,

Could this solution work for a device Tag, which is then used as configuration parameters on an Edge Workflow.

Tag Name - DeviceConfig1  
Tag Value - {“param1”:“12345”}

for example?

---

<div class="post-metadata">

**Author:** ![Sebastian\_Turner](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/sebastian_turner/32/4024_2.png) [@Sebastian\_Turner](https://forums.losant.com/u/Sebastian_Turner)\
**Post date:** [March 8, 2023, 7:19pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/10 "2023-03-08T19:19:19Z")

</div>

Yes, that would work, with the following considerations:

- There’s a 255 character limit for the tag value.
- The tag value would fail if not in valid JSON format, so validation testing is recommended.

---

<div class="post-metadata">

**Author:** ![ChrisGM](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@ChrisGM](https://forums.losant.com/u/ChrisGM)\
**Post date:** [March 8, 2023, 7:36pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/11 "2023-03-08T19:36:41Z")

</div>

Would it be possible to ask for an example?  
I did try this but I think my syntax was incorrect.

Would the JSON Decode Node work?

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [March 9, 2023, 3:27pm UTC](https://forums.losant.com/t/array-within-device-tag/4634/12 "2023-03-09T15:27:10Z")

</div>

Yes, the JSON: Decode Node would work for this. I’ve attached a sample application demonstrating this. Did you try this already and run into a problem?

[export-6409f9a1bb7fefb54cb22a22-1678375578716-forums4634.zip](https://forums.losant.com/uploads/short-url/ecFpVczsYlnpZStqIwCImVIHd18.zip) (2.5 KB)
