Re: [Jsonpath] Remarks on the array slice operator described in https://jsonpath-standard.github.io/internet-draft/#name-array-selector-2

Daniel P <danielaparker@gmail.com> Tue, 08 December 2020 19:47 UTC

Return-Path: <danielaparker@gmail.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 061003A110F for <jsonpath@ietfa.amsl.com>; Tue, 8 Dec 2020 11:47:13 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.098
X-Spam-Level:
X-Spam-Status: No, score=-2.098 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, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9Fw1MrHY4XJb for <jsonpath@ietfa.amsl.com>; Tue, 8 Dec 2020 11:47:08 -0800 (PST)
Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 80CDA3A110D for <jsonpath@ietf.org>; Tue, 8 Dec 2020 11:47:08 -0800 (PST)
Received: by mail-wm1-x333.google.com with SMTP id d3so2973710wmb.4 for <jsonpath@ietf.org>; Tue, 08 Dec 2020 11:47:08 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=RYTvCzTBI0zWeOLjLJ8YTFI74OFow1bUHjH5aLzj8XA=; b=J0t57T9EZfFpGdIMiF7MwhkLmoBhFe9POUUjmyvhwVeqtK8s/aJi4Gdg8BosM2Nouk /xg9M2yEDfbg+5jKtbJnNBr5Ilkqtx/Ww6vSwjt/tNAlvurKVq6UHN3TDPbGBx163hpN cZ3GxrLmZmYPuPC2ccPecn0+QeMnRFp+AdTG+Rc8aoh6j/UHyKUYRDZ1AgMV0ag/8AD4 d654F3wlzBSQESjiCc07L4PBV5QaL1fJqSw3goBwHlyGDRiH27POXyLbvAUaLleYU05+ 77ZdzEvQlVIeyLnDo3/3ZJ3oGJ3gNuzmugBo6+dubPqmK4uS9Ac6L0wSl8ubsPTEgpYg RbjQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=RYTvCzTBI0zWeOLjLJ8YTFI74OFow1bUHjH5aLzj8XA=; b=GQZIiSHTe8riQdbio9/NFFODedPMyupJAuIR2g2/vLLN/PhLhObO/npqNCgANSzCD4 ATLfPjRmTqThuH2NyzjCY6r6lvDj62GAlHWcHg2F3eWB0KHukabGKU+RTWRGeuXsP08+ M8LpZtRucKMIhxEZptU3TwYpDqg6AcrCzEoIi6EYxFZ+Z1t2g+aJnggORYXH/SLLp1xw FkTZobdaiw2WtDc2z79Kz8xgYCUb9UroDS0EBhx2s8rLc5jLSU4aUX4mihLnz9okw5gJ pkuXdS0IHTX+xpTtqlKfYqCgy1iVupjjQY6twzFOtnuxMSo/ASOEeV0jmKiXgoS/qMs1 j+0A==
X-Gm-Message-State: AOAM533tdkprlm4UZpnElo/mAWCB8ImsHzj2R1LI3eXLyV5cq/yNoFjr 9Qx33c6ske+OebSrCdjkFZ2wYuxCdosT4TP5S9o=
X-Google-Smtp-Source: ABdhPJydWhwS4n8JH3ygJro8S8dMOTy0XbQ/qbth01CTHQMIDr/fG+Ch2rPXcqnQiRtZec/109uNZzAlCLQqonRfBxQ=
X-Received: by 2002:a7b:c208:: with SMTP id x8mr5189383wmi.179.1607456826752; Tue, 08 Dec 2020 11:47:06 -0800 (PST)
MIME-Version: 1.0
References: <CA+mwktL4Lio1FKD+20K0rvqb8De9GQomaJy1F+cct=pj_Ft4VQ@mail.gmail.com> <89140FFF-6B25-4ABC-8A25-92327B1313F3@gmail.com> <E59DC723-B9A9-4A03-A3A9-0036DE6F7940@gmail.com> <CANH0GbJEk-RS_QNM_ZM78KCRv+QRUcFK8=oBxQgNtbW1zLLAvA@mail.gmail.com> <FAB83C6B-C878-4ECC-B392-2261A2B70477@saxonica.com>
In-Reply-To: <FAB83C6B-C878-4ECC-B392-2261A2B70477@saxonica.com>
From: Daniel P <danielaparker@gmail.com>
Date: Tue, 08 Dec 2020 14:46:55 -0500
Message-ID: <CA+mwktKCyuga6LBWDFON8tiUiCdyfo6ica1=QdtQftwY+pwgbA@mail.gmail.com>
To: Michael Kay <mike@saxonica.com>, Carsten Bormann <cabo@tzi.org>, Glyn Normington <glyn.normington.work@gmail.com>, jsonpath@ietf.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/jsonpath/s2P8ADcSJHXHgzmOMXzMq9aJHcw>
Subject: Re: [Jsonpath] Remarks on the array slice operator described in https://jsonpath-standard.github.io/internet-draft/#name-array-selector-2
X-BeenThere: jsonpath@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: A summary description of the list to be included in the table on this page <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, 08 Dec 2020 19:47:13 -0000

What about

result = search(json_instance, "#$@&%*! is that?");

If a JSONPath expression can't be parsed according to syntactical rules, would
"some kind of fallback behaviour" ever be helpful to a user? I can see
returning
"no results" if an otherwise valid expression cannot be evaluated against the
provided JSON instance, which many implementations do.

Daniel

On Tue, Dec 8, 2020 at 5:29 AM Michael Kay <mike@saxonica.com> wrote:
>
> My advice based on experience of XPath design mistakes would be: decide your policy on errors and then apply it consistently. Either try and minimise errors by making all meaningless constructs exhibit some kind of fallback behaviour, or maximise errors by making all meaningless constructs fail, but don't do it different ways for different errors.
>
> On the whole I think JSONPath is designed to be "forgiving", i.e. such things aren't errors, e.g. I think I read in the spec that filtering a non-array isn't an error, it's some kind of no-op. That approach isn't always best for everyone, but it's important to be consistent.
>
> Michael Kay
> Saxonica
>
> On 8 Dec 2020, at 09:31, Glyn Normington <glyn.normington.work@gmail.com> wrote:
>
> Did anyone else have an opinion on the behaviour of slices such as [::0]? The current draft allows this and says it returns an empty array, but there is good reason to say it should error so that the slice operation is then consistent with Python slicing. See below for more context.
>
> On Thu, 26 Nov 2020 at 10:22, Glyn Normington <glyn.normington.work@gmail.com> wrote:
>>
>> On 26 Nov 2020, at 09:49, Glyn Normington <glyn.normington.work@gmail.com> wrote:
>>
>>
>> (3) "When step is 0, no elements are selected. This is the one case
>> which differs from the behaviour of Python, which raises an error in
>> this case." p. 10
>>
>> Is there a rationale for that choice? As you note, in Python it is an
>> error. In JMESPath it is also an error, see
>> https://jmespath.org/specification.html#slices.
>>
>>
>> The rationale is the supposed consensus of implementations.
>>
>>
>> Unless I've missed it, Christoph Burgmer doesn't have a test case for
>> a slice where step is zero. Perhaps we can prevail upon him to add
>> one.
>>
>>
>> I will add that test.
>>
>>
>> It turns out there is such a test already, but no consensus:
>>
>> https://cburgmer.github.io/json-path-comparison/results/array_slice_with_step_0.html
>>
>> Maybe raising an error to be consistent with Python would be a good move. What do others think?
>>
> --
> Jsonpath mailing list
> Jsonpath@ietf.org
> https://www.ietf.org/mailman/listinfo/jsonpath
>
>