Repository navigation
Response search, JSONPath filtering and syntax highlighting - #3
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements two roadmap items: response search and JSONPath filtering, and syntax highlighting of request and response bodies.
JSONPath (RFC 9535)
TermRest.Core.Json(no new dependencies): names, indexes, slices, wildcards, descendants, filters with comparisons,&&,||,!, and the functionslength,count,match,searchandvalue, with RFC 9535's well-typedness checks.TERMREST_JSONPATH_CTS=<cts.json>).match/searchtake 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.1 == 1.0;9007199254740993≠9007199254740992); strings by code point.Unexpected 'T': expected a value, a query (@… or $…) or a function (character 11).BodyFilterapplies 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
text/plain), read-only text included; raw request bodies in their chosen language; GraphQL variables as JSON. Wrapped text is colored per whole line.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
win-x64: no warnings; 20.47 MiB (+0.19 MiB). Smoke-testedsnapshotandsend --filter(includingmatch/searchwith\p{L}).$..*(1.3 M values) takes 1.2 s, which the UI runs in the background.