search

Home  >  Q&A  >  body text

MySQL method to extract all keys in nested JSON string

<p>In addition to this answer, is it possible to extract nested keys in a simple way? Example: </p> <pre class="brush:php;toolbar:false;">{ "a": value, "b": { "c": value, "d": { "e": value } } }</pre> <p>Desired output: ['a', 'b.c', 'b.d.e'] What I've tried: </p> <pre class="brush:php;toolbar:false;">SELECT f.`id` AS `field_name` FROM table t, JSON_TABLE( JSON_KEYS(t.`column`, '$.b'), '$[*]' COLUMNS( `id` VARCHAR(191) PATH '$' ) ) AS t</pre> <p>But this will only show one of the nested keys and skip the outer keys. </p>
P粉257342166P粉257342166461 days ago499

reply all(1)I'll reply

  • P粉009186469

    P粉0091864692023-08-29 10:22:53

    db<>fiddle here

    reply
    0
  • Cancelreply