Bug #71230 Implement negative indexes for JSON functions
Submitted: 25 Dec 2013 21:07 Modified: 14 Aug 2014 0:03
Reporter: Sveta Smirnova Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: JSON User-defined function ( UDF ) Severity:S4 (Feature request)
Version:0.2.2, 0.3.0 OS:Any
Assigned to: Sveta Smirnova CPU Architecture:Any

[25 Dec 2013 21:07] Sveta Smirnova
Description:
Currently JSON functions do not support negative indexes. Please implement them as described at https://blogs.oracle.com/svetasmirnova/entry/last_element_for_json_array:

So, -1 means last element, -2 last before last and so on. 

I.e., for JSON document {"colors": ["red", "green", "blue"]} 

json_append(doc, 'colors', -1, 'orange') 
returns 
{"colors": ["red", "green", "blue", "orange"]} 

and 

json_set(doc, 'colors', -2, 'orange')
returns
{"colors": ["red", "green", "orange"]}. 

json_append returns original document in case of -2.

This feature should be implemented for all level of indexes for functions JSON_CONTAINS_KEY, JSON_EXTRACT, JSON_REMOVE, JSON_REPLACE, JSON_APPEND, JSON_SET

How to repeat:
See description.
[14 Aug 2014 0:03] Sveta Smirnova
Posted by developer:
 
Fixed in version 0.3.2