I have a MySQL (v5.7) database that has a table called deals which contains a JSON column called status.
Status contains data (in deals id = 29) in the following format (apologies for the formatting):
{
"trackStatus":
[
{
"date":[],
"notes":[],
"value":"0",
"isChecked":false
},
{
"date":["2019-03-25T17:42:45-04:00"],
"notes":[],
"value":4,
"isChecked":true
}
],
"nextStatusIndex":0,
"currentDealStatus":4
}
I am trying to query the trackStatus array where value = 4to find out if itisChecked`.
My understanding from reading the MySQL reference that I need to use the JSON_EXTRACT function to get the data.
In following some of the examples, I tested the query as follows to see if I could return trackStatus:
SELECT JSON_EXTRACT(status, '$.trackStatus')
FROM deals
WHERE deals.id = 29
This works and returns trackStatus. However, when I try to expand on this to query within trackStatus specifically for isChecked, it does not return a value (not null but blank).
SELECT JSON_EXTRACT(status, '$.trackStatus', '$.isChecked')
FROM deals
WHERE deals.id = 29 AND JSON_EXTRACT(status, '$.trackStatus', '$.value') = 4
I have tried a myriad of different queries to the point where I am going in circles.
I realize the issue is with trackStatus because if I remove that array, I can query nextStatusIndex and it works. However with the array there, it does not.
So I am hoping someone can show me how/if I can query this JSON using MySQL queries (both within trackStatus and nextStatusIndex) given the way the data is formatted.