David, This was discussed in the Working Group, but it wasn't felt that the added complexity was worth it; there's a strong feeling that this spec should be as simple as possible. Cheers, On 15/12/2012, at 4:54 AM, David J. Biesack <David.Biesack@xxxxxxx> wrote: > > I originally posted this in a "Re: Last Call: <draft-ietf-appsawg-json-patch-08.txt> (JSON Patch) to Proposed Standard" thread > but now I've read draft-ietf-appsawg-json-pointer-07 and have changed that suggestion to reflect draft-ietf-appsawg-json-pointer-07 > > Suggestion: allow negative numbers to indicate a position counted from the end of the array instead "array/-". > > For example, a/-1 to point to the last item in an array (length > 0), -2 to point to the penultimate item, and so on. > The notation -i is an alias for (array.length - i) > > It is an error if |i| > array length. > > For the json-patch "add" operation, use > > { "op" : "add", "path" : "...array/-1", "value" : value } > > to append to the end, "...array/-2" to insert before the last item, and so on. > The "path" is the path that the item will be addressed by after inserting it. > I.e. after appending to an array of length l at j < 0, the item will be at the zero-based index (l + 1) + j. > > E.g. given the document with an array of length 4: > > { "a" : [ 0, 1, 2, 3, ] } > > then > > { "op" : "add", "path" : "/a/-1", "value" : 99 } > > yields > > { "a" : [ 0, 1, 2, 3, 99] } > > i.e. 99 is found at (4 + 1) -1 == 4 > > > { "op" : "add", "path" : "/a/-2", "value" : 99} > > yields > > { "a" : [ 0, 1, 2, 99, 3] } > > i.e. 99 is found at (4 + 1) -2 == 3 > > and finally > > { "op" : "add", "path" : "/a/-5", "value" : 99 } > > yields > > { "a" : [ 99, 0, 1, 2, 3] } > > i.e. 99 is found at (4 + 1) -5 == 0 > > -- > David J. Biesack | Principal API Architect, SAS | @davidbiesack | 919-531-7771 | www.sas.com > -- Mark Nottingham http://www.mnot.net/