New Transparent capture is in preview. Record every app's traffic with no proxy configuration, on Windows, macOS and Linux. Learn more

jsonResponseFilter Filter

Select exchanges whose response body is JSON, identified by the response Content-Type header at the moment headers are parsed.

jsonResponseFilter selects exchanges whose response body is declared as JSON through the Content-Type header. It is the idiomatic selector for inspecting and rewriting REST API responses without affecting HTML pages or static assets. Pair it with any action below to tag, log or rewrite the data the server sends back.

When to use this filter

Reach for jsonResponseFilter when a rule should apply only to responses carrying a JSON body. It is the right selector for REST and JSON-RPC APIs where you want to act on the data the server returns rather than what the client sends.

Typical situations:

  • Tagging every JSON API response for easy review in the capture view.
  • Removing cache headers from JSON responses to force a fresh fetch on the next test run.
  • Logging the response status of JSON endpoints to a dedicated file.

The filter evaluates on the responseHeaderReceivedFromRemote scope, so the response headers are already known but the body has not yet been streamed back to the client. Combine it with statusCodeFilter or hostFilter for finer scoping.

Real world examples

Tag every JSON API response

Apply a tag to all responses with a JSON body so they group together in the Fluxzy capture view, making it easier to inspect REST API traffic.

rules:
- filter:
    typeKind: JsonResponseFilter
  actions:
  - typeKind: ApplyTagAction
    tag:
      value: json-response

Strip cache headers from JSON responses

Force the client to refetch JSON payloads on the next request by removing the cache control headers. Useful when debugging stale data issues.

rules:
- filter:
    typeKind: JsonResponseFilter
  actions:
  - typeKind: RemoveCacheAction

Log JSON responses returning an error status

Append a line to a file for every JSON response that comes back with a 5xx status code, useful when chasing intermittent server failures.

rules:
- filter:
    typeKind: FilterCollection
    children:
    - typeKind: JsonResponseFilter
    - typeKind: StatusCodeServerErrorFilter
  actions:
  - typeKind: FileAppendAction
    filename: /var/log/fluxzy/json-errors.log
    text: "{{exchange.url}} {{exchange.statusCode}}"

Reference

jsonResponseFilter

Description

Select exchanges having JSON response body. The content-type header is checked to determine if the content body is a JSON.

Evaluation scope

Evaluation scope defines the timing where this filter will be applied.

responseHeaderReceivedFromRemote This scope occurs the moment fluxzy has done parsing the response header.

YAML configuration name

jsonResponseFilter

Settings

This filter has no specific characteristic

The following table describes the customizable properties available for this filter:

Property Type Description DefaultValue
inverted boolean Negate the filter result false

Example of usage

The following examples apply a comment to the filtered exchange

Select exchanges having JSON response body. The content-type header is checked to determine if the content body is a JSON.

rules:
- filter:
    typeKind: JsonResponseFilter
  actions:
  - typeKind: ApplyCommentAction
    comment: filter was applied

.NET reference

View definition of JsonResponseFilter for .NET integration.

See also

The following filters are related to this filter:

Frequently asked questions

How does jsonResponseFilter recognize a JSON body?

It inspects the response Content-Type header. Any value containing application/json matches, which covers application/json, application/json; charset=utf-8 and vendored types such as application/vnd.api+json.

Does it inspect the response payload?

No. jsonResponseFilter only checks the Content-Type header. It will not parse the body content. Use a custom .NET filter if you need payload level matching.

When is the filter evaluated?

On the responseHeaderReceivedFromRemote scope, which fires as soon as Fluxzy finishes parsing the response headers from the upstream. The body has not yet been streamed back to the client at that point.

How does it differ from jsonRequestFilter?

jsonResponseFilter checks the response Content-Type, jsonRequestFilter checks the request Content-Type. Use the response side to act on what the server returns, and the request side to act on what the client sends.

Learn more about Fluxzy rules