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

jsonRequestFilter Filter

Select exchanges whose request body is JSON, identified by the Content-Type header, before forwarding to the upstream.

jsonRequestFilter selects exchanges whose request body declares itself as JSON through the Content-Type header. It is the idiomatic selector for REST APIs and JSON-RPC style services, and it pairs naturally with header and authentication actions. Use it whenever a rule should only run for the write side of a JSON API.

When to use this filter

Reach for jsonRequestFilter when a rule should only apply to requests carrying a JSON payload, identified by a Content-Type of application/json or one of its variants. It is the cleanest selector for REST API traffic that uses JSON as its wire format.

Typical situations:

  • Adding an authorization header to every JSON request hitting an internal API.
  • Tagging POST and PUT calls that carry JSON for triage in the capture view.
  • Appending a log line for each JSON request to feed offline analysis.

The filter evaluates on the requestBodyReceivedFromClient scope, so the request body has been fully received from the client before the filter fires. Combine it with methodFilter or pathFilter to scope to specific endpoints.

Real world examples

Add a bearer token to every JSON request to an API

Attach a bearer token to all JSON requests heading to the internal API host, while leaving non-JSON traffic alone.

rules:
- filter:
    typeKind: FilterCollection
    children:
    - typeKind: JsonRequestFilter
    - typeKind: HostFilter
      pattern: api.example.com
  actions:
  - typeKind: AddAuthorizationBearerAction
    token: dev-token-123

Tag JSON POST and PUT calls for review

Mark every JSON write call so they group together in the capture view, useful when auditing the mutation traffic of a single page application.

rules:
- filter:
    typeKind: JsonRequestFilter
  actions:
  - typeKind: ApplyTagAction
    tag:
      value: json-request

Reject JSON requests above a certain endpoint

Return a canned 415 response to every JSON request hitting an endpoint that should only accept form data, useful to validate client behavior under content negotiation.

rules:
- filter:
    typeKind: FilterCollection
    children:
    - typeKind: JsonRequestFilter
    - typeKind: PathFilter
      pattern: /upload
      operation: StartsWith
  actions:
  - typeKind: RejectWithStatusCodeAction
    statusCode: 415

Reference

jsonRequestFilter

Description

Select request sending JSON body. Filtering is made by inspecting value of Content-Type header

Evaluation scope

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

requestBodyReceivedFromClient This scope occurs the moment fluxzy received fully the request body from the client. In a fullstreaming mode which is the default mode, this event occurs when the full body is already fully sent to the remote server.

YAML configuration name

jsonRequestFilter

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 request header dnt: 1.

rules:
- filter:
    typeKind: RequestHeaderFilter
    headerName: dnt
    pattern: 1
    operation: Exact
  actions:
  - typeKind: ApplyCommentAction
    comment: filter was applied

Select exchanges issued by Chrome 112 by checking User-Agent.

rules:
- filter:
    typeKind: RequestHeaderFilter
    headerName: User-Agent
    pattern: 'Chrome/112 '
    operation: Contains
  actions:
  - typeKind: ApplyCommentAction
    comment: filter was applied

.NET reference

View definition of JsonRequestFilter for .NET integration.

See also

The following filters are related to this filter:

Frequently asked questions

How does jsonRequestFilter recognize a JSON body?

It inspects the request 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 parse the body content?

No. jsonRequestFilter only looks at the Content-Type header. It will not validate that the bytes actually parse as JSON. Use a custom .NET filter if you need payload level checks.

When is the filter evaluated?

On the requestBodyReceivedFromClient scope. The request body has been fully received from the client when the filter runs. In full streaming mode this also means the body has already been forwarded to the upstream.

How does it differ from jsonResponseFilter?

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

Learn more about Fluxzy rules