How to extract values from column of mysql table having partial Json array values and remaining with string values

172 Views Asked by At

sample pic of mysql table

Names of these 3 columns were Date, TargetName, Amount. TargetName column has partial rows with json array values and remaining rows with strings.

I want to extract value[0] from json array. With condition like [case when (targetName is Json type) Then $.value[0] else targetName] How to apply this condition and get the expected result?

Expected outcome: TargetName

SSC Stenographer

UP Police Sub Inspector

UPRVUNL JE

AAI JE Technical

ACC Exam

1

There are 1 best solutions below

4
On
SELECT CASE WHEN JSON_VALID(TargetName)
            THEN TargetName ->> "$[0].value"
            ELSE TargetName
            END AS TargetName ,
       ...