Skip to content

Response search, JSONPath filtering and syntax highlighting - #3

Merged
ShikeChen-MS merged 2 commits into
mainfrom
response-search
Nov 17, 2026
Merged

ShikeChen-MS merged 2 commits into
mainfrom
response-search

Conversation

@ShikeChen-MS

Copy link
Copy Markdown
Owner

Implements two roadmap items: response search and JSONPath filtering, and syntax highlighting of request and response bodies.

JSONPath (RFC 9535)

  • Own parser and evaluator in TermRest.Core.Json (no new dependencies): names, indexes, slices, wildcards, descendants, filters with comparisons, &&, ||, !, and the functions length, count, match, search and value, with RFC 9535's well-typedness checks.
  • Passes all 715 cases of the JSONPath Compliance Test Suite (opt-in test: TERMREST_JSONPATH_CTS=<cts.json>).
  • match/search take I-Regexp (RFC 9485), translated to .NET's non-backtracking (linear-time) engine and code-point correct: . and [^…] match an emoji whole, \p{L} matches letters beyond the BMP. ^/$ are anchors, as the suite expects.
  • Numbers compare exactly (1 == 1.0; 9007199254740993 ≠ 9007199254740992); strings by code point.
  • Errors say where a query goes wrong: Unexpected 'T': expected a value, a query (@… or $…) or a function (character 11).
  • BodyFilter applies a query to a response body as it is shown (charset decoding), treats NDJSON / JSON Lines as an array of records, and caps output size.

UI

  • Filter button in the response Body tab opens a JSONPath row. The body shows the selected values as a JSON array (pretty or compact), for this and later responses until closed. Invalid queries show the error while the last result stays; non-JSON bodies are shown as they are with the reason. Large bodies are filtered in the background (cancellable). Copy copies the values; Save as… still saves the raw body.
  • Find (Ctrl+F) from anywhere: a bar under the response searches the current tab's text (Body, Timeline, TLS, Scripts). All matches are highlighted; Enter/F3 and Shift+Enter/Shift+F3 select the next/previous match, going round; Match case; Esc closes. Works with wrapped text (matches spanning rows), and keeps the selected match when the pane is resized.
  • Syntax highlighting: new JSON and XML/HTML lexers. Responses are colored as their Content-Type says (or JSON/markup sniffed from text/plain), read-only text included; raw request bodies in their chosen language; GraphQL variables as JSON. Wrapped text is colored per whole line.
  • Ctrl+F no longer moves the cursor right in text fields (Terminal.Gui's Emacs binding), so it reaches Find.

CLI

  • termrest send … --filter '<jsonpath>' prints the selected values as a JSON array (one line with --raw, to a file with -o). An invalid query exits 2 before sending; a non-JSON body exits 1.

Verification

  • Windows: Core 789 passed (6 OS-specific skips), CLI 37 passed, TUI 286 passed.
  • Linux (WSL Ubuntu 24.04): 1109 passed, 11 Windows-only skips.
  • Native AOT win-x64: no warnings; 20.47 MiB (+0.19 MiB). Smoke-tested snapshot and send --filter (including match/search with \p{L}).
  • On a 9.5 MB body, typical queries take 0.1–0.5 s; $..* (1.3 M values) takes 1.2 s, which the UI runs in the background.

ShikeChen-MS and others added 2 commits November 17, 2026 12:37
…ighting

JSONPath (RFC 9535) filters JSON responses: a query selects values by name, index, slice, wildcard, descendants and filters (comparisons, &&, ||, !, and the functions length, count, match, search and value). It passes the 715 cases of the JSONPath Compliance Test Suite, an opt-in test (TERMREST_JSONPATH_CTS). match and search take I-Regexp (RFC 9485), turned into .NET's linear-time engine so that . and classes match a code point (an emoji whole; \p{Lu} matches 𝒜). Numbers compare exactly (1 == 1.0; 9007199254740993 is not 9007199254740992), strings by code point. In the UI, the Body tab's Filter shows a JSONPath row: the body shows the values the query selects as a JSON array, in each response until the row is closed. A large body is filtered in the background, NDJSON as an array of its lines, and Copy copies the values. termrest send --filter prints them (on one line with --raw, to a file with -o); a query that isn't JSONPath is a usage error, before anything is sent. Find (Ctrl+F from anywhere; text fields no longer take Ctrl+F as Emacs's cursor right) looks in the text of the tab shown, highlights every match and selects them in turn (F3 or Enter; Shift+F3 or Shift+Enter backwards). JSON, XML and HTML bodies are colored: a request's raw body in the language chosen for it, a response's as its Content-Type says, read-only and wrapped text too. When words wrap, a line is colored whole and its colors split over its rows.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The README describes the Body tab's colors and Filter, Find and its keys, send --filter and its exit codes, and the opt-in JSONPath compliance test, and drops them from the roadmap. The executable is about 20 MB (20.5 MiB on win-x64): no longer under.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@ShikeChen-MS
ShikeChen-MS merged commit 477ac0d into main Nov 17, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant