# Display Python or json formated string

**URL:** <https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 20, 2024, 5:41pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248 "2024-09-20T17:41:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 5:41pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/1 "2024-09-20T17:41:31Z")

</div>

This is a long shot.  
In perspecive, is there a way to display formatted object like below:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/5/750893b58788fe0848f1b5b7e0eceb6706932855.png)  
and  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/a/3a19872df49e4b1e0397a184c6123d6665c7be24.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/5/c55e8c3adea8778fbc42da7deb499c5415ada194.png)

---

<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:** [September 20, 2024, 5:43pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/2 "2024-09-20T17:43:17Z")

</div>

What do you mean ?  
Display where ? Formatted how ?

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 5:45pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/3 "2024-09-20T17:45:33Z")

</div>

Display as is.. in Beautified form, indented at least.

I wanted to show/display recipe..  
This recipe can be of different Object structure.

---

<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:** [September 20, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/4 "2024-09-20T17:46:12Z")

</div>

I have no clue what you mean.  
Do you want to display it in a view ? In the console ? In logs ?

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 5:47pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/5 "2024-09-20T17:47:14Z")

</div>

Of course.  
Display in a view.. can be seen on browser screen as is (formatted).

---

<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:** [September 20, 2024, 5:49pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/6 "2024-09-20T17:49:20Z")

</div>

There are a lot of ways to display things in a nice format.  
The simplest way might be to just use a label, set `whitespace: pre` in its styles, bind its text prop to your data and use a formatting function.  
Or you can use a flex repeater to have full control over each item.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 5:51pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/7 "2024-09-20T17:51:54Z")

</div>

I will test.  
I have these on Document Tags.  
I will bind markdown to this tag, probably need to convert first to string..  
Let me see..

---

<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:** [September 20, 2024, 5:52pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/8 "2024-09-20T17:52:49Z")

</div>

Yep, markdown sounds like a good idea.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 6:10pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/9 "2024-09-20T18:10:28Z")

</div>

hmm.. I am stuck.  
I wanted the markdown to look like the custom.object as it shown

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/5/c55e8c3adea8778fbc42da7deb499c5415ada194.png)

---

<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:** [September 20, 2024, 6:14pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/10 "2024-09-20T18:14:12Z")

</div>

What did you do to get this ?

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 6:17pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/11 "2024-09-20T18:17:50Z")

</div>

The source string come from `custom.object`  
-\> converted to json string via `system.util.jsonEncode(value, 20)`  
-\> feed this string to Text Area (So I can play with format)  
-\> feed output of text area to markdown (whitespace: pre)

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 6:21pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/12 "2024-09-20T18:21:24Z")

</div>

my bad..  
its working..  
But how do i format the incoming string? hmm

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/c/7ca7f5c03e11e17d719dbeece46fb2f15a389541.png)

---

<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:** [September 20, 2024, 6:22pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/13 "2024-09-20T18:22:11Z")

</div>

What format do you want ?

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 6:25pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/14 "2024-09-20T18:25:22Z")

</div>

The string initially looks like this:  
I had to manually, add `newline` and add `indent` using Text Area.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/7/c7a149bef8d1d1418eef396aec94039f94efa74e.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 20, 2024, 6:27pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/15 "2024-09-20T18:27:02Z")

</div>

Paste your JSON as formatted text so we don't have to type it all out again.  
Re-read Pascal's responses and try and answer his questions.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 6:28pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/16 "2024-09-20T18:28:22Z")

</div>

here you go:

```python
{
  "sfcNumber": "12345",
  "materials": 1,
  "requestId": "S0031",
  "location": "mpx",
  "priority": "Low",
  "department": "dept",
  "onHoldNotes": "on hold s0039",
  "status": "Completed"
}

```

---

<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:** [September 20, 2024, 6:31pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/17 "2024-09-20T18:31:13Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/3/436341b45b342ce7b96adc844dd4ef6e4f5551dc.png)

```python
def transform(self, value, quality, timestamp):
	longest = max(len(str(k)) for k in value.iterkeys()) + 2
	return '\n'.join("{k:.<{w}}{v}".format(k=k, v=v, w=longest) for k, v in value.iteritems())

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/8/c8e33838d932f398c576ed5db9da4087d118894e.png)

Go from there to get whatever result you want. Or describe it if you get stuck.

edit:  
Note that you get the exact same thing with a label, so as long as you want something basic, stick with a label.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 20, 2024, 6:58pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/18 "2024-09-20T18:58:15Z")

</div>

I now get it.. you need to cook it yourself..  
Thanks Thanks Thanks.  
Sorry.. But I found this:

> <https://stackoverflow.com/questions/11672018/json-string-formatting-with-python>

But I was unable to make it work yet... Will get back to this..

---

<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:** [September 20, 2024, 7:13pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/19 "2024-09-20T19:13:02Z")

</div>

> **[jsonFormat | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/JSON/jsonFormat)**
>
> Takes a string, and returns a prettyprints string

---

<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:** [September 20, 2024, 7:18pm UTC](https://forum.inductiveautomation.com/t/display-python-or-json-formated-string/96248/20 "2024-09-20T19:18:08Z")

</div>

Ah ! I knew there was something like that but I couldn’t find it. I guess I just missed it… thought I was going crazy and remembering things that didn’t exist !
