# User Importing and Exporting an Object From Perspective Project With 'Pretty' Formatting

**URL:** <https://forum.inductiveautomation.com/t/user-importing-and-exporting-an-object-from-perspective-project-with-pretty-formatting/81818>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [November 13, 2023, 5:20pm UTC](https://forum.inductiveautomation.com/t/user-importing-and-exporting-an-object-from-perspective-project-with-pretty-formatting/81818 "2023-11-13T17:20:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyler\_Dolan](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Tyler\_Dolan](https://forum.inductiveautomation.com/u/Tyler_Dolan)\
**Post date:** [November 13, 2023, 5:20pm UTC](https://forum.inductiveautomation.com/t/user-importing-and-exporting-an-object-from-perspective-project-with-pretty-formatting/81818/1 "2023-11-13T17:20:51Z")

</div>

Hello,

I have an object that is stored in a custom property in perspective that I want the user to be able to import and export as json formatted text. Correct me if I'm wrong, but as far as I know, there's no good way to download and upload a .txt file or pull from and push to the clipboard in Perspective. Because of that, I'm using a text area to copy and paste text to and from.

My problem is I'd like the text to have nice line breaks for easy reading. I currently have the text area text property bound to the desired object property and have it do a script transform `return system.util.jsonEncode(value, 4)`, but there are no newlines in the text area. I see from other forum posts that the text area supports html line breaks, but I'm guessing that's not what jsonEncode is doing.

Is there a good way to get pretty formatting of an object in a text area, or more broadly, is there a better way to have the user import and export an object represented as text for easy editing?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 13, 2023, 5:26pm UTC](https://forum.inductiveautomation.com/t/user-importing-and-exporting-an-object-from-perspective-project-with-pretty-formatting/81818/2 "2023-11-13T17:26:03Z")

</div>

> [@Using dict comprehension to append data](https://forum.inductiveautomation.com/t/using-dict-comprehension-to-append-data/77225/20):
>
> Regarding pretty printing of (assuming) dictionaries hopefully eases your pain a bit, I keep this in a project library so I can call it when needed. import pprint mydict = {'nest0':'hi', 'nest1':{'something':1}, 'nest2':{'nest1again':{'somethingelse':'bye'}} } pp = pprint.PrettyPrinter(depth=4) pp.pprint(mydict) [image] In my experince PyDataSets are most useful when you want access to all or almost all columns in a dictionary. So for things like for (someCol1, someCol2, someCol3…

If you want the string I think you can use `formattedString = pp.pformat(mydict)` to get the string.

Having said that there is also [https://docs.inductiveautomation.com/display/DOC81/system.perspective.download](https://docs.inductiveautomation.com/display/DOC81/system.perspective.download)

---

<div class="post-metadata">

**Author:** ![Tyler\_Dolan](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Tyler\_Dolan](https://forum.inductiveautomation.com/u/Tyler_Dolan)\
**Post date:** [November 13, 2023, 6:57pm UTC](https://forum.inductiveautomation.com/t/user-importing-and-exporting-an-object-from-perspective-project-with-pretty-formatting/81818/3 "2023-11-13T18:57:12Z")

</div>

I tried pprint in the script console and in the tag binding and it's not creating new lines when I follow the usage shown in the documentation.

I thought to use system.perspective.download as well, but I can't import as there is no system.perspective.upload

---

<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:** [November 13, 2023, 7:02pm UTC](https://forum.inductiveautomation.com/t/user-importing-and-exporting-an-object-from-perspective-project-with-pretty-formatting/81818/4 "2023-11-13T19:02:06Z")

</div>

I would probably recommend using the markdown component for this, then you can use HTML to format the text, including some styling for colors and other things, as you wish.

> [@Tyler\_Dolan](#):
>
> I thought to use system.perspective.download as well, but I can't import as there is no system.perspective.upload

You must use the file upload component to upload files in perspective.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 13, 2023, 7:12pm UTC](https://forum.inductiveautomation.com/t/user-importing-and-exporting-an-object-from-perspective-project-with-pretty-formatting/81818/5 "2023-11-13T19:12:16Z")

</div>

Also if you mean you can't `import system.perspective` in the script console that is because the script console is running on a variant of the vision scope, which doesn't have `system.perspective`.

---

<div class="post-metadata">

**Author:** ![Tyler\_Dolan](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Tyler\_Dolan](https://forum.inductiveautomation.com/u/Tyler_Dolan)\
**Post date:** [November 13, 2023, 7:22pm UTC](https://forum.inductiveautomation.com/t/user-importing-and-exporting-an-object-from-perspective-project-with-pretty-formatting/81818/6 "2023-11-13T19:22:39Z")

</div>

No, I meant that there is no system.perspective.upload.

Irose pointed out that there is a file upload component thought, which I did not know.

---

<div class="post-metadata">

**Author:** ![Tyler\_Dolan](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Tyler\_Dolan](https://forum.inductiveautomation.com/u/Tyler_Dolan)\
**Post date:** [November 13, 2023, 10:22pm UTC](https://forum.inductiveautomation.com/t/user-importing-and-exporting-an-object-from-perspective-project-with-pretty-formatting/81818/7 "2023-11-13T22:22:23Z")

</div>

Here is the solution I landed on. It seems that `system.util.jsonEncode` struggles to properly format the perspective tree object type, so you can first convert it to normal python types and then call `system.util.jsonEncode`

```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
	    
return system.util.jsonEncode(sanitize_tree(value),4)

```
