Arrayy icon indicating copy to clipboard operation
Arrayy copied to clipboard

Validate array based on a schema

Open szepeviktor opened this issue 3 years ago • 7 comments

What is this feature about (expected vs actual behaviour)?

Provide a schema a check validity of/fix an array.

@voku Do you happen to know a package that does this? Do you plan to implement it?

szepeviktor avatar Feb 10 '22 15:02 szepeviktor

Sounds interesting, what kind of schema did you think of?

voku avatar Feb 10 '22 16:02 voku

I'm not ready with the answer! JSON schema seems to be popular but it is complex. As far as I can see it needs only key type, value type and is_required. ...for trees and multidimensional arrays too

szepeviktor avatar Feb 10 '22 16:02 szepeviktor

are you talking about json validation?

rcsofttech85 avatar Aug 10 '23 13:08 rcsofttech85

Yes. But not exclusively.

szepeviktor avatar Aug 10 '23 14:08 szepeviktor

php has a json_validate function in its latest version ..fixing things for minor version does not make sense i guess..

rcsofttech85 avatar Aug 10 '23 14:08 rcsofttech85

@rcsofttech85 json_validate only validates the JSON, not the data in the JSON

@szepeviktor It's already possible to validate / extract multidimensional data from JSON e.g.
https://github.com/voku/Arrayy/blob/eaea4564b719812f8ac48ebbcd96cfffdcfa17de/tests/PHPStan/AnalyseTest.php#L14

voku avatar Aug 13 '23 01:08 voku

There is a tool for this https://github.com/coduo/php-matcher

smilesrg avatar Feb 09 '24 13:02 smilesrg