thephpleague / json-guard

Validation of json-schema.org compliant schemas.
http://json-guard.thephpleague.com/
MIT License
175 stars 26 forks source link

Native PHP array support #137

Closed HeathNaylor closed 6 years ago

HeathNaylor commented 6 years ago

In the Overview markdown, it is noted that array types are not supported by default.

In my use case, we are working with raw PHP array's to avoid memory bloat as we are operating on a large number of results.

Is there any reason we do not want to provide array support specifically?

matt-allan commented 6 years ago

Hello 👋

This is covered in the FAQ. http://json-guard.thephpleague.com/faq

If you decoded your json as an array (json_decode($data, true)), an empty object is decoded the same as an empty array; they both decode to []. This would make it impossible to validate “type”: “object” or “type”: “array” when the object/array is empty.

HeathNaylor commented 6 years ago

@yuloh so, for our scenario for the time being, would you say that creating our own rule set to operate on the array is the path forward?

matt-allan commented 6 years ago

You would probably need to change most of the library (and json-reference if using references).

You will also need to change the validator because it checks for an object, so just a rule set wouldn't work.