title: How do you use CONCAT within a JSON path for MySQL?
body: <p><strong>MySQL Version 5.7</strong></p>
  
  <p>Given that h.<code>ent_rollup</code> length is always >=4 and I want to get the second to the last array element in a JSON data field that only holds a single array:</p>
  
  <p>Example JSON value for <code>ent_rollup</code>:</p>
  
  <pre><code>["15","26","57","28","89","10","11","12"]
  </code></pre>
  
  <p>Example: I want this</p>
  
  <pre><code>SELECT h.`ent_rollup`-&gt;&gt;CONCAT('"$[',(JSON_LENGTH(h.`ent_rollup`))-2,']"') FROM hierarchy h
  </code></pre>
  
  <p>to translate to this</p>
  
  <pre><code>SELECT h.`ent_rollup`-&gt;&gt;"$[6]" FROM hierarchy h
  </code></pre>
  
  <p>I want to get <code>11</code> back but I'm getting this error:</p>
  
  <pre><code>Error Code: 1064
  You have an error in your SQL syntax; check the manual that corresponds to 
  your MySQL server version for the right syntax to use near 'concat('"$[', 
  (json_length(h.`ent_rollup`))-2,']"') from hierarchy h
  where h.`en' at line 1
  </code></pre>