1

In addition to this answer is it possible to extract nested keys in a simple way? Example:

{
  "a": value,
  "b": {
    "c": value
    "d": {
      "e": value
   } 
  }
}

Expected output: ['a', 'b.c', 'b.d.e'] What I have tried:

 SELECT 
 f.`id` AS `field_name`
 
 FROM table t,
    JSON_TABLE(
         JSON_KEYS(t.`column`, '$.b'),
         '$[*]' COLUMNS(
           `id` VARCHAR(191) PATH '$'
         )
     ) AS t

but that would only show me one of the nested keys and skip the outer

2
  • 2
    I think you might need a recursive CTE to do this. It will be easier in a real programming language, then you can write a recursive function. Commented Feb 8, 2022 at 9:18
  • Example - invalid JSON. Expected output - invalid JSON. Commented Feb 8, 2022 at 10:38

1 Answer 1

1
SELECT JSON_SEARCH(val, 'all', 'value') result
FROM test;
| result                      |
| :-------------------------- |
| ["$.a", "$.b.c", "$.b.d.e"] |

db<>fiddle here

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

Comments

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.