# Function to convert json string or python dict into ObjectWrapper

**URL:** <https://forum.inductiveautomation.com/t/function-to-convert-json-string-or-python-dict-into-objectwrapper/32861>\
**Category:** Ignition\
**Created:** [March 5, 2020, 10:45pm UTC](https://forum.inductiveautomation.com/t/function-to-convert-json-string-or-python-dict-into-objectwrapper/32861 "2020-03-05T22:45:39Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [May 5, 2021, 8:20pm UTC](https://forum.inductiveautomation.com/t/function-to-convert-json-string-or-python-dict-into-objectwrapper/32861/16 "2021-05-05T20:20:59Z")

</div>

Forcing each to the expected type while traversing makes a deep copy:

```auto
def sanitize_tree(element):
    if hasattr(element, ' __iter__'):
        if hasattr(element, 'keys'):
            return dict((k, sanitize_tree(element[k])) for k in element.keys())
        else:
            return list(sanitize_tree(x) for x in element)
    return element

```

EDIT: Got rid of the unnecessary zip() and used only one keys() iterator instead of two.

---

_[View the full topic](https://forum.inductiveautomation.com/t/function-to-convert-json-string-or-python-dict-into-objectwrapper/32861)._
