Closed HeathNaylor closed 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.
@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?
You would probably need to change most of the library (and json-reference if using references).
property_exists
calls to check for a property or an array keyis_object
checks to check for both objects and arraysis_array
checks to make sure it's an actual JSON array and not an objectYou will also need to change the validator because it checks for an object, so just a rule set wouldn't work.
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?