M
M
Mykola2022-04-06 11:52:16
MySQL
Mykola, 2022-04-06 11:52:16

How to extract id from json in string in SQL?

There is the following line in json format in a column in the database:

{"name": "Metallica", "@type": "Event", "image": ["https://site.com/data/images/54837687508image.jpeg"], "offers": {"url": "https://site.com/event/36302", "@type": "Offer", "price": "0", "validFrom": "2024-05-21T12:00", "availability": "https://schema.org/InStock", "priceCurrency": "BRL"}, "endDate": "2022-05-12UTC00:00", "@context": "https://schema.org", "location": {"name": "Estádio Mineirão", "@type": "Place", "address": {"@type": "PostalAddress", "streetAddress": "", "addressCountry": "UA", "addressLocality": "Belo Horizonte"}}, "organizer": {"url": "https://site.com", "name": "site.com", "@type": "Organization"}, "performer": {"name": "Metallica", "@type": "PerformingGroup"}, "startDate": "2022-05-12UTC00:00", "description": "jueves, 12 de mayo de 2022 | Estádio Mineirão", "eventStatus": "https://schema.org/EventScheduled", "eventAttendanceMode": "https://schema.org/OfflineEventAttendanceMode"}


From this line, you need to extract the event id, which is hidden in the url: "http s:/ / site.com/event/36302".
There are more than 20k such lines, please help in creating the procedure.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2022-04-06
@qnixit

select replace(data->'$.offers.url', 'https://site.com/event/', '') from test

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question