# StackOverflowError on jsonEncode of dict containing Dataset

**URL:** <https://forum.inductiveautomation.com/t/stackoverflowerror-on-jsonencode-of-dict-containing-dataset/117401>\
**Category:** Ignition\
**Created:** [October 8, 2026, 8:14pm UTC](https://forum.inductiveautomation.com/t/stackoverflowerror-on-jsonencode-of-dict-containing-dataset/117401 "2026-10-08T20:14:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eaolson](https://avatars.discourse-cdn.com/v4/letter/e/f07891/32.png) [@eaolson](https://forum.inductiveautomation.com/u/eaolson)\
**Post date:** [October 8, 2026, 8:14pm UTC](https://forum.inductiveautomation.com/t/stackoverflowerror-on-jsonencode-of-dict-containing-dataset/117401/1 "2026-10-08T20:14:16Z")

</div>

I need to persist some objects into my database and the quickest way seemed to be to convert them to JSON, then save that. That works ok with a Dataset, but fails on an object that contains a Dataset.

```python
d = system.dataset.toDataset(["foo"], [[1]])
print system.util.jsonEncode(d)
# {"columns":[{"name":"foo","type":"java.lang.Integer"}],"rows":[[1]]}

d2 = {"myDataset": d}
print system.util.jsonEncode(d2)
# RuntimeError: maximum recursion depth exceeded (Java StackOverflowError)

d3 = {"myDataset": system.dataset.toPyDataSet(d)}
print system.util.jsonEncode(d3)
# RuntimeError: maximum recursion depth exceeded (Java StackOverflowError)

```

Python's json.dumps also fails, even on the basic Dataset. Java's jackson returns a similar error to jsonEncode.

I'm surprised I couldn't find anything else on the forum about this. Does anyone have a workaround, or do I have to convert all the Datasets to Python dicts/lists myself first?

---

<div class="post-metadata">

**Author:** ![AIO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aio/32/87549_2.png) [@AIO](https://forum.inductiveautomation.com/u/AIO)\
**Post date:** [October 8, 2026, 8:20pm UTC](https://forum.inductiveautomation.com/t/stackoverflowerror-on-jsonencode-of-dict-containing-dataset/117401/2 "2026-10-08T20:20:46Z")

</div>

Relevant thread. Looks like encoding the dataset first may work.

> [@\[BUG-15901\] JSON encoding and decoding a "Dataset" datatype property](https://forum.inductiveautomation.com/t/bug-15901-json-encoding-and-decoding-a-dataset-datatype-property/31617):
>
> I am trying to pass a value of “Dataset” type as a value in a dictionary which I need to store in a “String” format. Assume the following: dataset: variable of type “Dataset” dict = {‘set’ : dataset} To build the string representation for the dictionary, I am using system.util.jsonEncode. When I try to retrieve the dictionary from its string representation using system.util.jsonDecode, I do not get the dataset back in “Dataset” type. Instead, I get a representation of it in some form. Is the…

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [October 8, 2026, 8:25pm UTC](https://forum.inductiveautomation.com/t/stackoverflowerror-on-jsonencode-of-dict-containing-dataset/117401/3 "2026-10-08T20:25:09Z")

</div>

I can’t remember when it changed but a Dataset is now also interchangeable with a pyDataset.  
Encode the dataset then add it to the dict as json, then it should work.  
I believe the conversion may not work correctly unless it can detect the Dataset type directly.

---

<div class="post-metadata">

**Author:** ![Rats](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rats/32/68478_2.png) [@Rats](https://forum.inductiveautomation.com/u/Rats)\
**Post date:** [October 8, 2026, 9:36pm UTC](https://forum.inductiveautomation.com/t/stackoverflowerror-on-jsonencode-of-dict-containing-dataset/117401/4 "2026-10-08T21:36:46Z")

</div>

That happened when the version 8.1.x jumped to 8.3.x.

If on 8.3 and below, this does not apply.

[Link to change](https://www.docs.inductiveautomation.com/docs/8.3/getting-started/installing-and-upgrading/ignition-8-upgrade-guide/81to83-upgrade-guide#system-function-changes-and-deprecations:~:text=Note%20that%20this%20function%20has%20been%20deprecated%20because%20datasets%20no%20longer%20need%20to%20be%20manually%20wrapped%20as%20PyDatasets.%20This%20change%20also%20impacts%20system.dataset.toDataSet%20from%208.1%2C%20which%20now%20has%20only%20a%20single%20syntax%20and%20should%20be%20written%20as%20system.dataset.toDataset%20in%208.3.)

---

<div class="post-metadata">

**Author:** ![eaolson](https://avatars.discourse-cdn.com/v4/letter/e/f07891/32.png) [@eaolson](https://forum.inductiveautomation.com/u/eaolson)\
**Post date:** [October 9, 2026, 3:09pm UTC](https://forum.inductiveautomation.com/t/stackoverflowerror-on-jsonencode-of-dict-containing-dataset/117401/5 "2026-10-09T15:09:40Z")

</div>

Yeah, so far that seems to be the only solution. My problem with that approach is now you don't have an object containing a dataset, you have an object containing a string representation of a dataset, which you can then encode to JSON. That means you can't cleanly go backwards. I mean, if you want to decode that JSON, you can't just run jsonDecode on it, you have to know that additionally, certain strings have to be left as strings and others need to be decoded further. Basically, you need a schema at that point.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 9, 2026, 3:28pm UTC](https://forum.inductiveautomation.com/t/stackoverflowerror-on-jsonencode-of-dict-containing-dataset/117401/6 "2026-10-09T15:28:54Z")

</div>

There is essentially no penalty for converting to a pyDataSet. I would just do that.

I would probably write a wrapper functions which traverse the object and convert all the datasets prior to calling jsonEncode, then then do the oposite calling jsonDecode and then traversing the object and converting back to datasets.
