# Perspective JSON as parameter for script

**URL:** <https://forum.inductiveautomation.com/t/perspective-json-as-parameter-for-script/52353>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 26, 2021, 3:15pm UTC](https://forum.inductiveautomation.com/t/perspective-json-as-parameter-for-script/52353 "2021-10-26T15:15:18Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 2, 2021, 9:03am UTC](https://forum.inductiveautomation.com/t/perspective-json-as-parameter-for-script/52353/18 "2021-11-02T09:03:17Z")

</div>

This code creates a deepcopy (the correct way):

> [@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.

If you put it in a project script it should be easyenough to use

```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
		    
	obj = sanitize_tree(self.view.custom.test)
			
	obj['val_1']['index'] +=1
	obj['val_1']['index'] +=1
	obj['val_1']['index'] +=1
	obj['val_1']['index'] +=1
	obj['val_1']['index'] +=1
	
	self.view.custom.test = obj

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/perspective-json-as-parameter-for-script/52353)._
