# Convert Param Object to PyDictionary

**URL:** <https://forum.inductiveautomation.com/t/convert-param-object-to-pydictionary/67590>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [December 14, 2022, 3:46am UTC](https://forum.inductiveautomation.com/t/convert-param-object-to-pydictionary/67590 "2022-12-14T03:46:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_Weston](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Samuel\_Weston](https://forum.inductiveautomation.com/u/Samuel_Weston)\
**Post date:** [December 14, 2022, 3:46am UTC](https://forum.inductiveautomation.com/t/convert-param-object-to-pydictionary/67590/1 "2022-12-14T03:46:06Z")

</div>

I'm trying to create a template that opens a popup with a dynamic parameter set. The issue I've run into is that the system.perspective.openPopup function only accepts a dictionary to define the parameters, but I want to use an object in my template params called 'PopupParams'.

Essentially I need to convert 'PopupParams' to a dictionary, right now I accomplish that by encoding then decoding the object as a json string, removing the object wrapper.

```auto
	PopupParams = self.view.params.PopupParams
	ParamString = system.util.jsonEncode(PopupParams)
	ParamDict = system.util.jsonDecode(ParamString)
	system.perspective.openPopup(self.view.params.PopupID, self.view.params.PopupPath, params = ParamDict)

```

It works fine, but it's very gross, is there a better solution?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 14, 2022, 12:21pm UTC](https://forum.inductiveautomation.com/t/convert-param-object-to-pydictionary/67590/2 "2022-12-14T12:21:17Z")

</div>

Where and how is the object defined ? What's its exact type ?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 14, 2022, 5:51pm UTC](https://forum.inductiveautomation.com/t/convert-param-object-to-pydictionary/67590/3 "2022-12-14T17:51:09Z")

</div>

`dict(self.view.params.PopupParams)` might work; if it's not a deep dictionary.

If you do need a deep copy, you could try the approaches mentioned here:

> [@Copy dictionary and modify it without affecting the original](https://forum.inductiveautomation.com/t/copy-dictionary-and-modify-it-without-affecting-the-original/62297/9):
>
> As @bkarabinchak.psi pointed out even though the structure “looks” like a dict it isn’t actually a dict. Actually the type of a perspective property when accessed from a script is:[com.inductiveautomation.perspective.gateway.script.PropertyTreeScriptWrapper.ObjectWrapper](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.1/com/inductiveautomation/perspective/gateway/script/PropertyTreeScriptWrapper.ObjectWrapper.html). Thus deepcopy chokes when it runs into an object that it doesn’t know how to handle. If you need a true deepcopy, then you have couple of options. Write a function which recursively loops through the structure and correctl…

Or you could use [Ignition Extensions'](https://forum.inductiveautomation.com/t/ignition-extensions-convenience-utilities-for-advanced-users/64615) `system.util.deepCopy`.

---

<div class="post-metadata">

**Author:** ![Samuel\_Weston](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Samuel\_Weston](https://forum.inductiveautomation.com/u/Samuel_Weston)\
**Post date:** [December 14, 2022, 10:16pm UTC](https://forum.inductiveautomation.com/t/convert-param-object-to-pydictionary/67590/4 "2022-12-14T22:16:39Z")

</div>

Thanks, I think creating my own recursive deep copy function is the way to go, better visibility to other developers in my team. Unfortunately, we're unable to use community extensions as a restriction by our clients.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 14, 2022, 10:20pm UTC](https://forum.inductiveautomation.com/t/convert-param-object-to-pydictionary/67590/5 "2022-12-14T22:20:14Z")

</div>

Actually, if you're going that way I kinda prefer @justin.brzozoski's duck-typing approach:

> [@Function to convert json string or python dict into ObjectWrapper](https://forum.inductiveautomation.com/t/function-to-convert-json-string-or-python-dict-into-objectwrapper/32861/16):
>
> Forcing each to the expected type while traversing makes a deep copy: 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.

---

<div class="post-metadata">

**Author:** ![Samuel\_Weston](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Samuel\_Weston](https://forum.inductiveautomation.com/u/Samuel_Weston)\
**Post date:** [December 14, 2022, 10:37pm UTC](https://forum.inductiveautomation.com/t/convert-param-object-to-pydictionary/67590/6 "2022-12-14T22:37:37Z")

</div>

I remember seeing that last week although I couldn't quite wrap my head around it then, @pascal.fragnoud 's explanation in the other thread helped to clear up the confusion. Thanks mate.
