I am having trouble understanding how to select attributes from mysql json, my record is like this:
CREATE TABLE configuration (
name varchar(100) NULL,
version varchar(100) NULL,
trees json NULL
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci;
One insert:
INSERT INTO configuration VALUES ('test-config', 'version-default', '{
"trees": [
{
"tree_id": "TEST_TREE",
"site_id": "MSI",
"nodes": [
{
"node_version": 5,
"children_right": 3,
"node_position": 1,
"type": "root",
"node_id": "ROOT_TEST",
"children_left": 2
},
{
"node_version_id": 4,
"children_right": null,
"node_position": 2,
"type": "empty",
"node_id": "TEST_LEFT",
"children_left": null
},
{
"node_version_id": 61,
"children_right": null,
"node_position": 3,
"type": "empty",
"node_id": "TEST_RIGHT",
"children_left": null
}
],
"version": 1
}
],"status":"PENDING"
}');
Now if for example I want to select the field status from the json I can do the following:
SELECT trees->'$.status' AS status FROM configuration c;
But if I want to select for example the element 0 from the trees json array and then select the tree_id, how could I do this?
I was trying:
SELECT trees->'$.trees.[0].tree_id' AS trees FROM configuration c;
but no luck
And what if I want to go even deeper to the nodes json array?
Thank you in advance!