I want to use a counter to loop through JSON data in mysql, but I keep getting this error:
"code": "ER_INVALID_JSON_PATH",
"errno": 3143,
"sqlMessage": "Invalid JSON path expression. The error is around character position 2.",
"sqlState": "42000",
"index": 0,
Sample table from created_slots. It is a JSON Array that contains times This is the response i got from Postman:
"slots": "[\"11:00:00.000000\", \"12:00:00.000000\", \"12:30:00.000000\", \"13:00:00.000000\", \"13:30:00.000000\", \"14:00:00.000000\", \"14:30:00.000000\", \"15:00:00.000000\", \"15:30:00.000000\", \"16:00:00.000000\", \"16:30:00.000000\", \"17:00:00.000000\", \"17:30:00.000000\"]"
Note: created_slots is a JSON Array
It appears counter is not a valid reference. Is there a way to parse it in the string. This is my code below:
IF c_time > start_time THEN
removal_loop : LOOP
IF JSON_EXTRACT(created_slots, '$[loop_counter]') <> 0 THEN
IF JSON_EXTRACT(created_slots, '$[loop_counter]') < c_time THEN
SET created_slots = JSON_REMOVE(created_slots, '$[loop_counter]');
SET loop_counter = loop_counter + 1;
ELSE
SET loop_counter = loop_counter + 1;
END IF;
ELSE
LEAVE removal_loop;
END IF;
END LOOP removal_loop;
END IF;
Alternative solution:
IF JSON_EXTRACT(m_begin, '$[*]') < c_time THEN
SET created_slots = JSON_REMOVE(m_begin, '$[refernece to current item]')
... remove here, but I can't use this line of code because everything
will be deleted. I need a reference to the item that is less than
c_time