2

I have a MySQL DB containing a table named "products". This table contains a Json Data_type column named "values".

I would like to find the path to extract a specific value :

select JSON_EXTRACT(values, '$.COD') from products where id = '1'

returns :

"COD": {"<channels>": {"<locales>": "3699999999999"}}

And what I want is "3699999999999".

It is pretty obvious that my path is not the good one, but I can't find the solution.

Thanks for your help !

5
  • 3
    Hello and welcome. As newcomer reading of How to Ask and minimal reproducible example is good practice to learn how to ask a good question. For this case, you should provide the table schema. Commented Aug 31, 2018 at 10:04
  • 1
    try with $.COD.<locales> Commented Aug 31, 2018 at 10:14
  • Thank you, I tried, but I get an error regarding the '<' and '>' chars : "Invalid JSON path expression. The error is around character position 26." Commented Aug 31, 2018 at 12:30
  • Try dbfiddle. Commented Sep 1, 2018 at 10:10
  • You rock wchiquito ! How did I miss it ? Anyway, is there a way to select your answer as solution ? Commented Sep 3, 2018 at 9:04

1 Answer 1

1

You can try

SELECT JSON_EXTRACT(`values`, '$.COD.<channels>.<locales>') FROM products WHERE id = '1';

For more details please refer mysql-for-your-json

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I tried it but I get an error regarding the special chars '<' and '>'. "Invalid JSON path expression. The error is around character position 26."
Could you please try with backticks as <channels>.<locales>
Thanks again, I tried ---> select JSON_EXTRACT(values, '$.COD.<channels>.<locales>') and ----> JSON_EXTRACT(values, '$.COD.<channels>.<locales>') but same error twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.