Reputation: 31
Ex of value: [{‘test’:’https://‘,’id’,’2521’,’Shipment’}]
I would only want to return Shipment as the value returned for that field
Upvotes: 0
Views: 1310
Reputation: 365
I would avoid unnecessary arrays and use substr/insrt whenever possible
select substr(components, instr(components, "’", -1, 2) + 1, instr(components, "’", -1, 1) - instr(components, "’", -1, 2) - 1)
from (select "[{‘test’:’https://‘,’id’,’2521’,’Shipment’}]" components)
Upvotes: 0
Reputation: 31
Solution:
SPLIT(components, "'")[SAFE_OFFSET(ARRAY_LENGTH(SPLIT(components, "'")) - 2)]
Upvotes: 3
Reputation: 172993
Use below instead
array_reverse(split(translate(components, '[]{}', '')))[offset(0)]
Upvotes: 1