# Ignition 8 : error writing dictionnary to a Document Tag

**URL:** <https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [June 16, 2020, 2:29pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705 "2020-06-16T14:29:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [June 16, 2020, 2:29pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705/1 "2020-06-16T14:29:48Z")

</div>

**Ignition 8.0.13**  
When I try to write a gateway **Document Tag** with a dictionnary, I have the following error:

```auto
dico = {"test" : "10"}
system.tag.writeBlocking(["[default]path/to/tag"],[dico])

```

```auto
[Error_TypeConversion("Cannot coerce to document from class type 'class org.python.core.PyDictionary'")]

```

What’s wrong ?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [June 16, 2020, 3:21pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705/2 "2020-06-16T15:21:47Z")

</div>

I don’t know why but there’s no auto-conversion from a Python Dictionary to JSON when writing to Document tags.

Encode your dictionary with `system.util.jsonEncode` before writing it.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [June 16, 2020, 6:07pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705/3 "2020-06-16T18:07:54Z")

</div>

To clarify, you also need to convert it into a dictioanary when reading it as well if you want to manipulate it.  
i.e.

```auto
documentTag = system.tag.readBlocking([tagPath])[0].value
document = system.util.jsonDecode(str(documentTag))

```

If you dont do this then the DocumentObject wrapping the top level keeps you from being able to write to anything inside the document

So to edit the document you have to go through the following steps:

1. Read the tag
2. Cast it as a string
3. jsonDecode it into a dictionary
4. manipulate the dictionary
5. jsonEncode it back into a string
6. Write your changes back to the tag

Feels a bit overcomplicated, but I would just assume that the auto-conversion would probably be a good feature request, as with the rise of perspective, document tags are going to start becoming a lot more popular.

---

<div class="post-metadata">

**Author:** ![matt.eaton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matt.eaton/32/72046_2.png) [@matt.eaton](https://forum.inductiveautomation.com/u/matt.eaton)\
**Post date:** [December 18, 2020, 7:11pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705/4 "2020-12-18T19:11:31Z")

</div>

You can skip steps 2 and 3 in the response from kgamble above. The read document value has a .toDict() function to jump to a dictionary, then modify, encode and write back.

---

<div class="post-metadata">

**Author:** ![Riccardo\_Giampaolo](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@Riccardo\_Giampaolo](https://forum.inductiveautomation.com/u/Riccardo_Giampaolo)\
**Post date:** [February 4, 2025, 3:48pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705/5 "2025-02-04T15:48:53Z")

</div>

I know this is pretty old, but is there any improvement (or plan to) over document tags?I feel like they could be a great tool to store proper serialisable types, but fighting with encoding/decoding all the time makes almost plain strings more appealing. Thanks!

---

<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:** [February 4, 2025, 3:54pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705/6 "2025-02-04T15:54:13Z")

</div>

I just started playing with Document tags last year, and haven't needed any JSON encoding/decoding. Just wrapping in `dict()` on read, and writing a `dict()`. What have you tried lately?

---

<div class="post-metadata">

**Author:** ![Riccardo\_Giampaolo](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@Riccardo\_Giampaolo](https://forum.inductiveautomation.com/u/Riccardo_Giampaolo)\
**Post date:** [February 4, 2025, 4:06pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705/7 "2025-02-04T16:06:41Z")

</div>

Hey @pturmel , thank you so much as usual for the super quick feedback. Indeed, after some trying, I finally managed to write objects/lists and even perspective properties properly in a document tag.

Here is a fun behaviour I found tho. I had inadvertently set up a document field to Object (e.g. [Tag Provider]DocumentTag['default'] was set to object).

When testing to write a perspective property (of type ArrayWrapper) to it, instead of returning a write failed, the object "default" got converted to type value, and the arraywrapper was converted to string and assigned to it.

This threw me off a bit, and therefore led me to believe some proper conversion was not yet in place for the document tags. I do believe the correct behaviour for this would be to either refuse the write, or convert to the proper Array type.

I will probably open a separate topic for this tho.

---

<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:** [February 4, 2025, 4:14pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705/8 "2025-02-04T16:14:09Z")

</div>

I would only expect complete writes of the entire tag to work, and only using actual jython dictionaries and lists. Perspective properties are not native jython data types, so I would expect them to always fail in this way.

There are a number of topics here showing how to deep copy Perspective objects into programmer-friendly jython objects. You can also use helpers from my Integration Toolkit to do this.

---

<div class="post-metadata">

**Author:** ![Riccardo\_Giampaolo](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@Riccardo\_Giampaolo](https://forum.inductiveautomation.com/u/Riccardo_Giampaolo)\
**Post date:** [February 4, 2025, 4:16pm UTC](https://forum.inductiveautomation.com/t/ignition-8-error-writing-dictionnary-to-a-document-tag/35705/9 "2025-02-04T16:16:35Z")

</div>

I agree, that's why a "write but with inconsistent type" threw me completely off.

I will follow through on a different thread then, and I will check your helpers. Thanks for the support.
