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

"David J. Biesack" <David.Biesack@sas.com> Fri, 14 December 2012 17:54 UTC

Return-Path: <David.Biesack@sas.com>
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 2348B21F8A05 for <ietf@ietfa.amsl.com>; Fri, 14 Dec 2012 09:54:26 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -3.677
X-Spam-Level:
X-Spam-Status: No, score=-3.677 tagged_above=-999 required=5 tests=[AWL=-0.078, BAYES_00=-2.599, RCVD_IN_DNSWL_LOW=-1]
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 NXcPzq+Ap2Ry for <ietf@ietfa.amsl.com>; Fri, 14 Dec 2012 09:54:25 -0800 (PST)
Received: from ch1outboundpool.messaging.microsoft.com (ch1ehsobe001.messaging.microsoft.com [216.32.181.181]) by ietfa.amsl.com (Postfix) with ESMTP id 5CB7B21F89A9 for <ietf@ietf.org>; Fri, 14 Dec 2012 09:54:25 -0800 (PST)
Received: from mail26-ch1-R.bigfish.com (10.43.68.234) by CH1EHSOBE007.bigfish.com (10.43.70.57) with Microsoft SMTP Server id 14.1.225.23; Fri, 14 Dec 2012 17:54:24 +0000
Received: from mail26-ch1 (localhost [127.0.0.1]) by mail26-ch1-R.bigfish.com (Postfix) with ESMTP id 788674A024D for <ietf@ietf.org>; Fri, 14 Dec 2012 17:54:24 +0000 (UTC)
X-Forefront-Antispam-Report: CIP:149.173.6.147; KIP:(null); UIP:(null); IPV:NLI; H:mercav04d.na.sas.com; RD:mercav04d.na.sas.com; EFVD:NLI
X-SpamScore: 0
X-BigFish: S0(zzzz1de0h1202h1e76h1d1ah1d2ahzz18602eh8275bhz2fh2a8h668h839h944hcf6hd24hf0ah1220h1288h12a5h12a9h12bdh137ah13b6h1441h1504h1537h153bh162dh1631h1758h1155h)
Received-SPF: pass (mail26-ch1: domain of sas.com designates 149.173.6.147 as permitted sender) client-ip=149.173.6.147; envelope-from=David.Biesack@sas.com; helo=mercav04d.na.sas.com ; d.na.sas.com ;
Received: from mail26-ch1 (localhost.localdomain [127.0.0.1]) by mail26-ch1 (MessageSwitch) id 1355507662705851_24075; Fri, 14 Dec 2012 17:54:22 +0000 (UTC)
Received: from CH1EHSMHS023.bigfish.com (snatpool3.int.messaging.microsoft.com [10.43.68.228]) by mail26-ch1.bigfish.com (Postfix) with ESMTP id A9E37160062 for <ietf@ietf.org>; Fri, 14 Dec 2012 17:54:22 +0000 (UTC)
Received: from mercav04d.na.sas.com (149.173.6.147) by CH1EHSMHS023.bigfish.com (10.43.70.23) with Microsoft SMTP Server (TLS) id 14.1.225.23; Fri, 14 Dec 2012 17:54:21 +0000
X-TM-IMSS-Message-ID: <9a672f980019a396@mercav04d.na.sas.com>
Received: from d72933.na.sas.com.na.sas.com ([10.23.16.81]) by mercav04d.na.sas.com ([10.36.10.9]) with ESMTP (TREND IMSS SMTP Service 7.1) id 9a672f980019a396 ; Fri, 14 Dec 2012 12:54:20 -0500
From: "David J. Biesack" <David.Biesack@sas.com>
To: ietf@ietf.org
Subject: draft-ietf-appsawg-json-pointer-07 - array index for end ofarray
Date: Fri, 14 Dec 2012 12:54:17 -0500
Message-ID: <p1obhwldti.fsf@d72933.na.sas.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-OriginatorOrg: sas.com
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: Fri, 14 Dec 2012 18:16:36 -0000

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