Hi Doug,
if I read the JSON document correctly, it's not very practical to read the contents of the document with JSON_QUERY.
Your problem are the many JSON arrays with []-notation. This means, the elements between the square brackets are repeatable. It's not guaranteed that you only receive ONE label back from UPS - according to the JSON structure, you can receive multiple labels/documents in the response.
So I would try to process the whole document with JSON_TABLE instead. Here I have a small example for you:
select *
from json_table(
'{"transactionId":"cabe21a2-8eb3-4359-9be7-ae841fbcac85","output"...',
'lax $' --> JSON "root"
columns (
transaction_id varchar(50) path 'lax $.transactionId',
nested path 'lax $.output.transactionShipments[*]'
columns (
master_tracking_number varchar(50) path 'lax $.masterTrackingNumber',
service_type varchar(50) path 'lax $.serviceType',
nested path 'lax $.pieceResponses[*]'
columns (
tracking_number varchar(50) path 'lax $.trackingNumber',
nested path 'lax $.packageDocuments[*]' --> here are the labels
columns (
encoded_label varchar(32000) path 'lax $.encodedLabel', --> probably base64 encoded
doc_type varchar(50) path 'lax $.docType',
copies_to_print integer path 'lax $.copiesToPrint'
)
)
)
)
);
I hope the code is somehow clear - the first parameter of JSON_TABLE has to be your JSON document. And you can use the SELECT in a SQL cursor and read all lines with FETCH.
If you insist in reading the label content with JSON_QUERY, the JSON path to the first(!) label of the first(!) parcel should be:
'lax $.output.transactionShipments[0].pieceResponses[0].packageDocuments[0].encodedLabel'
HTH and kind regards,
Daniel