Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Adds Str::isJson #42545

Merged
merged 4 commits into from
May 30, 2022
Merged

[9.x] Adds Str::isJson #42545

merged 4 commits into from
May 30, 2022

Conversation

ecrmnn
Copy link
Contributor

@ecrmnn ecrmnn commented May 27, 2022

Adds isJson() to Str and Stringable.

Str::isJson($data); 
//=> boolean

Str::of($data)->isJson()
//=> boolean

str($data)->isJson();
//=> boolean

Uses JSON_THROW_ON_ERROR flag introduced in PHP 7.3 under the hood.

@ecrmnn ecrmnn marked this pull request as ready for review May 27, 2022 14:50
@ecrmnn
Copy link
Contributor Author

ecrmnn commented Jun 4, 2022

@florisbosch

By it self '' isn't valid JSON.

json_decode('', false, 512, JSON_THROW_ON_ERROR);

// [THROWS] JsonException with message 'Syntax error'

null isn't valid because this is a string helper, therefore null will never be valid because it's not a string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants