Print to screen?

Hello - I have a JSON query that is returning a bunch of data to a string called alljson. All I want to do is output this to the screen. In the script console I can just use print alljson it spits everything out perfectly.

I want to do this in a perspective tag event script. I know I could write the output to a file, then display the file but wondering if there is a simpler way to do this?


I would create a memory tag with the document datatype and write your JSON data to it from the script that puts the JSON data together. You could then just bind your preferred text component in any view directly to the tag’s value to display it.

Just a note on working with document tag types: You will need to use the system.util.jsonDecode() (I think; but I may have that backwards and Encode might be the one you want) to convert your JSON data to a format that the document tag type will accept. If your JSON data contains any complex data types (e.g. arrays or objects) or is particularly large, this function will fail. The workaround I have found to work most reliably is doing something like the following:

from com.inductiveautomation.ignition.common import TypeUtilities

tagPath = '[default]Document_Tag'
value = unicode(TypeUtilities.pyToGson(jsonData))

It’s not clear what the data structure is and how you want it displayed but a single-row table might suit you. Try this:

  1. Drop a Table component onto your view.
  2. You need to assign your JSON data to the table’s This could be done most easily by
    • Creating a Named Query to retrieve your data.
    • Add a binding to your table’s
    • Set the Binding Type to Query.
    • Select the previously created query from the Query dropdown.
    • Edit the table properties to get it looking just right.
  3. Alternately you can get your script to write to the table’s

Thanks to all for the suggestions. I ended up using Transistor’s suggestion and writing to a table.