I think what has been proposed so far is powerful enough to perform that task *if* there is an intermediate object in the mix.
if ( // Assuming a dual pattern for JsonString.of and the SAP // strategy outlined in the doc json instanceof index(0, JsonString::of).decode(var firstName) ) { } On Wed, May 21, 2025 at 1:26 PM Maurizio Cimadamore < maurizio.cimadam...@oracle.com> wrote: > > On 21/05/2025 18:06, Paul Sandoz wrote: > > It was a design choice to be consistent with each json value having an > X, accepting X in on construction and producing X out (notionally) on > deconstruction, which leans into pattern matching. Definitely pros/cons > to that e.g., we could instead make JonObject implement Map, or do as > you suggest [*], both of which adjust how one reasons about the X in and > X out. > > I agree with this. When I wrote, I thought that it might be possible to > address some of these use cases using instance pattern declaration on the > array class (e.g. having an instance pattern that extracts the i-th element > of a JSONArray) -- but the instance pattern proposals we have discussed so > far [1] are not powerful enough to model that use case. > > Maurizio > > [1] - > https://openjdk.org/projects/amber/design-notes/patterns/towards-member-patterns >