[Jsonpath] Index selector [-0] non-existent end of an array?

Joel Bruner <joel@brunerd.com> Tue, 05 March 2024 07:56 UTC

Return-Path: <joel@brunerd.com>
X-Original-To: jsonpath@ietfa.amsl.com
Delivered-To: jsonpath@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 9EE19C14F616 for <jsonpath@ietfa.amsl.com>; Mon, 4 Mar 2024 23:56:34 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7.103
X-Spam-Level:
X-Spam-Status: No, score=-7.103 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=brunerd.com
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 43pODf-KA92V for <jsonpath@ietfa.amsl.com>; Mon, 4 Mar 2024 23:56:31 -0800 (PST)
Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id CF27CC14F693 for <jsonpath@ietf.org>; Mon, 4 Mar 2024 23:56:30 -0800 (PST)
X-Sender-Id: dreamhost|x-authsender|joel@brunerd.com
Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 0EFE64C2730 for <jsonpath@ietf.org>; Tue, 5 Mar 2024 07:56:30 +0000 (UTC)
Received: from pdx1-sub0-mail-a227.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 9F9E94C2125 for <jsonpath@ietf.org>; Tue, 5 Mar 2024 07:56:29 +0000 (UTC)
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1709625389; a=rsa-sha256; cv=none; b=X5s5IDFKDItCoc8ihb6roVb5MnYF4zOkh3dCV0jiKa5CDsgK65DWMgs3br/0pVEBqiMibh LRBwsHlmjRlYHTigawinsP3cLf0+pjlVgghCZvwpTeneHzLDYGQ8xbRia2AuSZWyEy+VGQ xb2xOQ7rYxt93tqHqFB9QEAIqWgdaYcxpH9N8wN8IwqNe/q6eiBFGawbvkLdh24Qyr0PcK El+dPGS1axc+11PfCedkDVNA4eYfF5ZXprry0tqCfKhsN5sfTRdC3wWNTllXRCO5B8AOaZ qw9oypHkzBvYC9Jg3+fN1EaMr8/WDnui950xasQkvJK0oonh59xrweNQEjjX0A==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1709625389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: dkim-signature; bh=GA9zGtzLAfQp8wkWXYqrArXgQ1fpjuqSEFxMs9/3trk=; b=clMdPC5HFpH7pfNXE8RpLmxBYm7T8nxL11ST1A1SArNB1XSosuSTtI+ek/i54HHGCxhywV gA2GY/roGYWNaBJj5YsJZ/QvXc/s0t+nOaMIurig0Ma/lFr75OOIFWXz8GhULtvZoAsEu2 V2T7aZMfpRz6QaPJDzMkYl2UEQvd+81j4l/w79hB8qDN8YEnTe9QExjSvmvKOvAqhrU1Q2 ZP5RoLJw1zNUTsKAJgVf6Yzgn62kk3Dc4S8tL1GUF/Vlhr2E9L5quB3iFmbiboJUJOpPH4 Osb6bMW83DU+c104cxYyMIKFMvOOhI3IGCMnyZ85hXlt920QxN+hBDLGR0frlg==
ARC-Authentication-Results: i=1; rspamd-55b4bfd7cb-t6svs; auth=pass smtp.auth=dreamhost smtp.mailfrom=joel@brunerd.com
X-Sender-Id: dreamhost|x-authsender|joel@brunerd.com
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|joel@brunerd.com
X-MailChannels-Auth-Id: dreamhost
X-Hysterical-Tart: 6dd203d74669f8b8_1709625389888_3588135140
X-MC-Loop-Signature: 1709625389888:4094431957
X-MC-Ingress-Time: 1709625389888
Received: from pdx1-sub0-mail-a227.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.124.220.170 (trex/6.9.2); Tue, 05 Mar 2024 07:56:29 +0000
Received: from smtpclient.apple (104-57-90-24.lightspeed.cicril.sbcglobal.net [104.57.90.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: joel@brunerd.com) by pdx1-sub0-mail-a227.dreamhost.com (Postfix) with ESMTPSA id 4TpnvK2W4KzGw for <jsonpath@ietf.org>; Mon, 4 Mar 2024 23:56:29 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brunerd.com; s=dreamhost; t=1709625389; bh=GA9zGtzLAfQp8wkWXYqrArXgQ1fpjuqSEFxMs9/3trk=; h=From:Content-Type:Subject:Date:To; b=LPbWVhO3IFGq/yMWhwwlSJSfI0fZAzDNNLHTr6Gz09hTXujfIWVawZ9tyhfM6VVpO ++XnaogKmEJyLxAbLUnp9EmaVqJsfqIJTpWiM6pNMfO4FRYdK/atexNWAH6u3INV8R BLeSQdxQQMB8Rb41h4RpuXWPc1sBQ/6RudlnFAU/DNUb+Kc5O0m/PRjodZyXfVYqtB 5zcznJtwap1CkvZqUir4YX3EFoPQeyBXNKAGn6RigXPWaHRNvmDj50/IgE286/7xJe BQCeWHyjInUnY7u9NzaMP8f7Zekh7xqr1DjazX+O9DaFQX11R/0Sut4ykKkjxjqvGx A13xRKyG0ivMw==
From: Joel Bruner <joel@brunerd.com>
Content-Type: multipart/alternative; boundary="Apple-Mail=_22B33CD6-7046-4580-A8CC-9A4E59A9CFB7"
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.400.31\))
Message-Id: <E002AA3B-F3F6-4F6E-8DF6-6E727E237291@brunerd.com>
Date: Tue, 05 Mar 2024 01:56:16 -0600
To: jsonpath@ietf.org
X-Mailer: Apple Mail (2.3774.400.31)
Archived-At: <https://mailarchive.ietf.org/arch/msg/jsonpath/PV7xwsB3aRhMyXtbQliquHKBMgM>
Subject: [Jsonpath] Index selector [-0] non-existent end of an array?
X-BeenThere: jsonpath@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: Discussion of JSONPath syntax <jsonpath.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/jsonpath>, <mailto:jsonpath-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/jsonpath/>
List-Post: <mailto:jsonpath@ietf.org>
List-Help: <mailto:jsonpath-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/jsonpath>, <mailto:jsonpath-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 05 Mar 2024 07:56:34 -0000

The other day someone was asking me how to insert a value at the end an array (using my jpt tool)… so I said something like: "Well in JSON Pointer it's "/-" and for JSONPath I borrowed the convention and use $[-]"… to which they replied "the spec seems to indicate it should be [-0]" – which had me quite puzzled since when brought this up in 2022 <https://mailarchive.ietf.org/arch/browse/jsonpath/?q=index%20selector%20like%20json%20pointer> it was deemed out of scope by some and nonsensical to others.

While in "2.3.3.2. Semantics" it is somewhat implied since the $[-1] is the end of an array and it does follow that $[-0] is after that, the ABNF for "2.3.3.2. Semantics" seems to explicitly exclude -0 only allowing "-" with digits 1-9

>  An index selector <index> matches at most one array element value.
>  index-selector      = int                        ; decimal integer
>  int                 = "0" /
>                         (["-"] DIGIT1 *DIGIT)      ; - optional
>  DIGIT1              = %x31-39                    ; 1-9 non-zero digit

Only later in "Figure 2" of "Appendix A" and in "2.3.5.1. Syntax" does "-0" make an appearance since this is a "signed zero" that Javascript allows but JSON can't roundtrip <https://mailarchive.ietf.org/arch/msg/json/RRT0jWUruScN1oXlgZlTqETivSU/> 
> number              = (int / "-0") [ frac ] [ exp ] ; decimal number

So it seems there really is no syntax for the non-existent end of an array in JSONPath – and for a while I was kind of excited there had been a change of heart.

When I look back I see Greg Dennis had this well meaning thing to say:

> I think this is the crucial point: JSON Path is intended as only a query language.  It's not intended to specify a location for days to be set/inserted.

Yet, two years later and it seems folks still haven't "gotten the memo" and are using JSONPath syntax not just for querying but for specifying locations to insert data. Why shouldn't they?  It's like approaching this by saying "People are the problem, the spec is just fine". JSON Point4er RFC6901 managed to define this very useful thing with a couple sentences in its 8 pages, yet in the 62 pages of the JSONPath spec somehow this is out of scope? It's such a simple thing to define, why not? I don't think it's a slippery slope to define either [-] or [-0] as the non-existent end of an array… two years ago I should have pushed back harder. The things not defined now will just mutate down the road.

Thanks,
Joel Bruner