From e28dd609c1f22267f7c594c72cd3525f2d2b7654 Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Mon, 4 May 2026 23:25:12 -0700 Subject: [PATCH] Add comma-disambiguated array literals --- README.md | 25 +++++++ get.go | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++-- get_test.go | 118 ++++++++++++++++++++++++++++++++ 3 files changed, 325 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7048fe6..b18acad 100644 --- a/README.md +++ b/README.md @@ -401,11 +401,20 @@ The query language supports: - Array indexing & slicing `foo.items[1:2].name` - Including negative indexes `foo.items[-1].name` - Array filtering via [mexpr](https://github.com/danielgtaylor/mexpr) `foo.items[name.lower startsWith d]` +- Array construction `[foo.id, foo.name]` - Object property selection `foo.{created, names: items.name}` - Recursive search `foo..name` - Stopping processing with a pipe `|` - Flattening nested arrays `[]` +Square brackets are context-sensitive in queries. At the beginning of a query or +object field value, a `[` expression constructs an array only when it contains a +top-level comma, so `[id, name]` returns a two-item array with those query +results. Single-element and empty array construction are not supported. A `[` +after an existing path indexes, slices, or filters that value, as in `items[0]`, +`items[:2]`, or `items[status == active]`. An empty bracket expression, `[]`, +keeps its existing meaning and flattens nested arrays one level. + The query syntax is recursive and looks like this: