Insert JSON String into Power Table

I have a JSON string stored in a database column. I would like to display this information in a power table on a vision screen. I am looking for a good way to do this. Any thoughts?

[{"PartNumber": "212C1031P102", "FullOrder": "15220593", "Index": 0, "tableID": 151}, {"PartNumber": "212C1031P102", "FullOrder": "15220593", "Index": 1, "tableID": 151}]

Hmm. You can use the configureCell extension method to return a java Swing component to render the cell. You could construct a JPanel with MigLayout and a collection of labels with that content. You'll have to play with row and column width settings to make it look nice, I suspect.

1 Like

You're wanting to import the database columns that contain data like your sample with the keys as the header names and the values as the data in the table?

A sufficiently enterprising person could construct a com.inductiveautomation.ignition.client.jsonedit.JsonEditor at runtime, for a nice JSON editing/viewing experience. That'd make for a fun Vision component, too... :thinking:

I suspect the actual task here is closer to what @justinedwards.jle is describing, though, so the JSON is basically immaterial; it's just a flat array of key:value pairs. I would just normalize the JSON to a proper Ignition dataset via scripting. Then you use the table as normal.

2 Likes

/me dodges the nerd snipe....

1 Like

I was able to parse the JSON string out with a simple SQL query in the bindings.

DECLARE @JsonMsg nvarchar(max)

Select @JsonMsg = [PartsList]

FROM [ABB_Housing].[dbo].[RawStockRecordTable]
WHERE [TrackingNum] = {Root Container.TrackingNum}

SELECT * FROM OpenJson(@JsonMsg)
WITH ( [Index] int,
[PartNumber] VARCHAR(100),
[FullOrder] VARCHAR(100),
[tableID] bigint )
ORDER BY [Index]

2 Likes