Skip to content

Commit

Permalink
Minor formatting adjustments to documentation
Browse files Browse the repository at this point in the history
Co-authored-by: Frank Brückner <[email protected]>
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel and froschdesign committed Jan 27, 2023
1 parent c9a6c48 commit e2fa8fe
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/book/validators/is-json-string.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# IsJsonString Validator
# IsJsonString

`Laminas\Validator\IsJsonString` allows you to validate whether a given value is a string that will be successfully decoded by `json_decode`.

Expand All @@ -15,7 +15,7 @@ if ($validator->isValid($input)) {
}
```

## Restricting Acceptable JSON types
## Restricting Acceptable JSON Types

`json_decode` accepts numeric strings representing integers and floating point numbers, booleans, arrays and objects.
You can restrict what is considered valid input using the `allow` option of the validator.
Expand All @@ -32,9 +32,9 @@ $validator->isValid('true'); // false

The `allow` option is a bit mask of the `ALLOW_*` constants in `IsJsonString`:

- `IsJsonString::ALLOW_INT` - Accept numeric such as "1"
- `IsJsonString::ALLOW_FLOAT` - Accept numeric strings such as "1.234"
- `IsJsonString::ALLOW_BOOL` - Accept "true" and "false"
- `IsJsonString::ALLOW_INT` - Accept integer such as `1`
- `IsJsonString::ALLOW_FLOAT` - Accept floating-point value such as `1.234`
- `IsJsonString::ALLOW_BOOL` - Accept `true` and `false`
- `IsJsonString::ALLOW_ARRAY` - Accept JSON arrays such as `["One", "Two"]`
- `IsJsonString::ALLOW_OBJECT` - Accept JSON objects such as `{"Some":"Object"}`
- `IsJsonString::ALLOW_ALL` - A convenience constant allowing all of the above _(Also the default)_.
Expand All @@ -46,7 +46,7 @@ use Laminas\Validator\IsJsonString;

$validator = new IsJsonString();
$validator->setAllow(IsJsonString::ALLOW_ARRAY | IsJsonString::ALLOW_OBJECT);
$validator->isValid("1.234"); // false
$validator->isValid('1.234'); // false
```

## Restricting Max Object or Array Nesting Level
Expand Down

0 comments on commit e2fa8fe

Please sign in to comment.