Skip to content

Selectors: JSONPath filters, recursive descent, negative index and multi-value headers #44

Closed

Description

@dataGriff

Why

body.$.<path> is a gjson subset translated by ToGJSON (internal/selector/selector.go:79-111): dotted paths, [n], ["quoted"], # and *. Real JSONPath users (Hurl, Postman, Bruno) also write filters, recursive descent, negative indexes and slices, and those fail to parse today. Headers only expose the first value.

What

Support, with the same syntax in # @assert, # @capture, the BDD the response body "<path>" steps and MCP:

  • body.$..id (recursive descent; gjson has no .., so implement a small in-tree walker for this form and document the choice)
  • body.$.items[?(@.done == true)].id and [?(@.name =~ /^a/)] (map onto gjson #(done==true)#.id and #(name%"a*"))
  • body.$.items[-1], body.$.items[1:3]
  • .length as an alias of # for people arriving from JavaScript
  • header.<name>.# (count) and header.<name>[1] (n-th value) for multi-valued headers such as Set-Cookie and Link

Errors name the unsupported construct and the line. validate uses the same parser so a bad selector is caught before running.

Where

internal/selector/selector.go, selector_test.go; internal/bdd/steps.go (paths without $.).

Docs

docs/format.md (Selectors table), docs/cheatsheet.md, docs/testing.md (body paths paragraph).

Tests

Table-driven ToGJSON cases with the expected gjson path and the expected value on a fixture document; multi-value header cases; parse-error messages.

Activity

  1. dataGriff commented on Sep 24, 2026

    @dataGriff
    OwnerAuthor

    Done in #114 (66832fb, review fixes in 42eaed0). Rather than mapping onto gjson queries, body.$ paths are read by a small in-tree JSONPath evaluator over gjson values (internal/selector/path.go): .., filters with == != < <= > >= =~ && || and presence, [-1], slices, wildcards, .length, and header.<name>.# / header.<name>[n]. gjson's items.0.id and items.#.id still select what they did. The choice is documented in docs/format.md#body-paths; validate uses the same parser.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions