简体   繁体   中英

JSON_EXTRACT and square brackets

I am not able to use (mysql) JSON_EXTRACT on a JSON record like:

[{"id": 156, "betas": [{"id": 324, "title": "mario", "gammas": [{"id": 190, "path": "file.png"}]}]}]

In particular I fails to get into the innermost square brackets:

SELECT JSON_EXTRACT(main, '$[0].betas.$[0]') FROM mydb.mytable;

returns NULL . I tried with a number of variants, but I fails to get the right one.

I note that SELECT JSON_EXTRACT(main, '$[0].betas') ... returns

[{"id": 324, "title": "mario", "gammas": [{"id": 190, "path": "file.png"}]}]  

$ refers to the root of the JSON object, it doesn't make sense to have $[0] in the middle of the path.

Try:

SELECT JSON_EXTRACT(main, '$[0].betas[0]') FROM mydb.mytable

This should return

{"id": 324, "title": "mario", "gammas": [{"id": 190, "path": "file.png"}]}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM