I am trying to extract json from database, but I am guessing there is malformed json there, and some of them is not valid json, or not exist at all, so I try to do something like this:
SELECT JSON_EXTRACT(json_column, '$.payload.from') as was,
JSON_EXTRACT(json_column, '$.payload.to') as now
FROM orders
WHERE JSON_EXTRACT(json_column, '$.action') = 'change'
AND JSON_EXTRACT(json_column, '$.payload.from') IS NOT NULL
AND JSON_EXTRACT(json_column, '$.payload.to') IS NOT NULL
AND JSON_EXTRACT(json_column, '$.action') IS NOT NULL
AND JSON_VALID(json_column) = 1;
but I am still getting error: "Invalid JSON text in argument 1 to function json_extract: "Invalid value." at position 0."
any thoughts on how to skip this error for malformed JSON row?
SELECT json_column FROM ordersshould show the JSON that is stored in the column json_column. Then you can check if the JSON is valid, and correct it (or delete it... )