Json

Validates that a value has valid JSON syntax.

Applies to

property or method

Class

Symfony\Component\Validator\Constraints\Json

Validator

Symfony\Component\Validator\Constraints\JsonValidator

Basic Usage

The Json constraint can be applied to a property or a “getter” method:

Options

message

type: string default: This value should be valid JSON.

This message is shown if the underlying data is not a valid JSON value.

payload

type: mixed default: null

This option can be used to attach arbitrary domain-specific data to a constraint. The configured payload is not used by the Validator component, but its processing is completely up to you.

For example, you may want to use several error levels to present failed constraints differently in the front-end depending on the severity of the error.