Re: draft-ietf-appsawg-json-pointer-07 - array index for end ofarray

Mark Nottingham <mnot@mnot.net> Mon, 17 December 2012 00:33 UTC

Return-Path: <mnot@mnot.net>
X-Original-To: ietf@ietfa.amsl.com
Delivered-To: ietf@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 0F0DC21F87BD for <ietf@ietfa.amsl.com>; Sun, 16 Dec 2012 16:33:48 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -103.996
X-Spam-Level:
X-Spam-Status: No, score=-103.996 tagged_above=-999 required=5 tests=[AWL=-1.397, BAYES_00=-2.599, USER_IN_WHITELIST=-100]
Received: from mail.ietf.org ([64.170.98.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YH65rc7FtfSI for <ietf@ietfa.amsl.com>; Sun, 16 Dec 2012 16:33:47 -0800 (PST)
Received: from mxout-08.mxes.net (mxout-08.mxes.net [216.86.168.183]) by ietfa.amsl.com (Postfix) with ESMTP id 5ED8521F8782 for <ietf@ietf.org>; Sun, 16 Dec 2012 16:33:47 -0800 (PST)
Received: from [192.168.1.80] (unknown [118.209.33.170]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTPSA id 32126509B5; Sun, 16 Dec 2012 19:33:45 -0500 (EST)
Content-Type: text/plain; charset="us-ascii"
Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\))
Subject: Re: draft-ietf-appsawg-json-pointer-07 - array index for end ofarray
From: Mark Nottingham <mnot@mnot.net>
In-Reply-To: <p1obhwldti.fsf@d72933.na.sas.com>
Date: Mon, 17 Dec 2012 11:33:41 +1100
Content-Transfer-Encoding: quoted-printable
Message-Id: <6B4F2945-EC54-4171-92FF-3A88CEB27D23@mnot.net>
References: <p1obhwldti.fsf@d72933.na.sas.com>
To: "David J. Biesack" <David.Biesack@sas.com>
X-Mailer: Apple Mail (2.1499)
Cc: ietf@ietf.org
X-BeenThere: ietf@ietf.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id: IETF-Discussion <ietf.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/ietf>, <mailto:ietf-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/ietf>
List-Post: <mailto:ietf@ietf.org>
List-Help: <mailto:ietf-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/ietf>, <mailto:ietf-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 17 Dec 2012 00:33:48 -0000

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@sas.com> 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/