Skip to content

Json::validate as an equivalent of json_validate #317

Description

@Marian-Kechlibar

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions