ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Run-Time variable Key JSON Parsing

Will this solution work? Parse JSON to Cluster - NI Community
It seems like it's possible but it would be creating a VI for each result?
Do you think I could I manage some raw string parsing to return the predictions value as an array instead of objects?

PS, I do know how to handle the JSON string into a cluster, if it were a constant structure.

I'm trying to handle the results of an AI inference in LandingAI's Landing edge. The inference result payload is a JSON formatted string. (either by using their web API and HTTP or by reading a .json file it generates).  The "predictions" object is variable. Each time it runs it returns different keys, so I'm lost, how to handle it. 
Payload 1:
{"type":"ObjectDetectionPrediction","predictions":{"4adc9111-c13e-4ee0-9e44-ad945447d94f":{"score":0.7076729,"labelIndex":1,"defectId":208450,"labelName":"Ding","coordinates":{"xmin":1111,"xmax":1144,"ymin":596,"ymax":621}},"c1e50fcb-89e4-4673-a7d9-32a3fbd18ecb":{"score":0.3431902,"labelIndex":1,"defectId":208450,"labelName":"Ding","coordinates":{"xmin":1325,"xmax":1353,"ymin":550,"ymax":574}}},"metadata":{"image_id":"","inspection_station_id":"","location_id":"","capture_timestamp":"2024-09-21T07:17:45.7689464-05:00"},"model_id":"354f3887-f9eb-413b-aaee-97d80a51c068","latency":{"decoding_s":0.0094819,"preprocess_s":0.0018961,"waiting_s":8E-07,"infer_s":0.6588475,"postprocess_s":2.38E-05}}

Payload 2:
{"type":"ObjectDetectionPrediction","predictions":{"834c9ac4-fef0-4c51-ad36-208c73794270":{"score":0.7076729,"labelIndex":1,"defectId":208450,"labelName":"Ding","coordinates":{"xmin":1111,"xmax":1144,"ymin":596,"ymax":621}},"8b89faf1-6067-49e1-8f81-3c0cd8319c09":{"score":0.3431902,"labelIndex":1,"defectId":208450,"labelName":"Ding","coordinates":{"xmin":1325,"xmax":1353,"ymin":550,"ymax":574}}},"metadata":{"image_id":"","inspection_station_id":"","location_id":"","capture_timestamp":"2024-09-21T07:17:56.7923955-05:00"},"model_id":"354f3887-f9eb-413b-aaee-97d80a51c068","latency":{"decoding_s":0.0080896,"preprocess_s":0.0024012,"waiting_s":9E-07,"infer_s":0.6673403,"postprocess_s":3.43E-05}}

If no object was detected, predictions are an empty object:
{"type":"ObjectDetectionPrediction","predictions":{},"metadata":{"image_id":"","inspection_station_id":"","location_id":"","capture_timestamp":"2024-09-21T07:32:28.3631828-05:00"},"model_id":"354f3887-f9eb-413b-aaee-97d80a51c068","latency":{"decoding_s":0.0063953,"preprocess_s":0.0021194,"waiting_s":1E-06,"infer_s":0.6943869,"postprocess_s":1.08E-05}}

0 Kudos
Message 1 of 4
(939 Views)
Message 2 of 4
(891 Views)

You can do it in one go with JSONText if you define the "predictions" as a map.

0 Kudos
Message 3 of 4
(855 Views)

Thank you. I am exploring the add-in and learning the Path notation. I have no experience with the Map datatype. I assume if would figure out how to use it and the 'Find Item (as LVType)"?
In the mean-time, it looks like I can find predictions by Name and just use the array length to determine accept reject. I'll expect I'll need to work towards checking a size threshold against the coordinates as well. 

0 Kudos
Message 4 of 4
(836 Views)