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

Json::validate as an equivalent of json_validate #317

Open
Marian-Kechlibar opened this issue Oct 9, 2024 · 0 comments
Open

Json::validate as an equivalent of json_validate #317

Marian-Kechlibar opened this issue Oct 9, 2024 · 0 comments

Comments

@Marian-Kechlibar
Copy link

Marian-Kechlibar commented Oct 9, 2024

PHP 8.3 comes with a new function json_validate which only tests if a string is valid JSON without actually parsing it into objects.
I believe it would be nice to have Nette\Utils\Json::validate as well, even if it was just a simple wrapper around json_validate, mostly for aesthetic purposes.

Currently, you must do a try-catch around Json::decode in order to validate a JSON. This sort-of breaks the visual flow of the code, plus is somewhat more expensive than Json::validate would be, if your only need is the validation, and you don't really need the fully parsed result.

Possibly, Json::validate could act more like a pure function and return a list of encountered problems instead of modifying the global state, which is what json_validate does.

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

No branches or pull requests

1 participant