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
"Array value found, but an array is required" #523
Comments
I think I understand what's going on. It's because it is receiving an associative PHP array but it wants an indexed array. It makes it confusing because they are the same 'type' in PHP. You actually have to go through the effort to check if you want to know if something is associative vs indexed in PHP.
Or something of the sort. |
Can you please provide a (minimal) schema sample that produces this error? |
Schema (test.json):
Data: Code:
Output: |
@adjenks Thanks for that - definitely looks like something we ought to improve on. Out of curiosity, why are you forcing |
I just forced json_decode to use an array to demonstrate the problem when you are already working with an array. |
Hi @adjenks, I tried to make this test fail:
but it doesn't. On which PHP version are you? I'm on PHP 7.2. |
@antodippo You can't cast a string to an object the way you are attempting to do - you just end up with an Use |
To clarify - the object that results from using |
@antodippo
So it's not a string anymore, and it's also not a a decoded json-object. So although casting a string to an object does not initially throw an error, I'm not sure what it's useful for. |
Hi, I have the same problem :
My json is : {
"@id":"\/product_variants",
"@type":"hydra:Collection",
"hydra:member":[
{
"@id":"\/product_variants\/my_product",
"@type":"ProductVariant",
"code":"my_product",
"position":0,
"createdAt":"2019-08-05T16:09:13+00:00",
"updatedAt":null,
"optionsValues":[
{
"@id":"\/product_option_values\/1",
"code":"age_class_children",
"optionCode":"age_class",
"position":0
},
{
"@id":"\/product_option_values\/3",
"code":"class_ordinary",
"optionCode":"class",
"position":1
},
{
"@id":"\/product_option_values\/5",
"code":"duration_seven",
"optionCode":"duration",
"position":2
}
]
}
]
} And my simplified shcema in order to get the error : {
"type": "object",
"required": [
"@id",
"@type",
"hydra:member"
],
"properties": {
"hydra:member": {
"type": "array",
"items": {
"type": "object",
"required": [
"@id",
"@type",
"code",
"position",
"createdAt",
"updatedAt",
"optionsValues"
]
}
}
}
} How can we validate a collection of object ? EDIT : sorry it's not really the same issue. If I indicate that my type is an array for my hydra:member items, the schema is valid. But for me this should be an object. |
I'm receiving this error message:
I don't quite understand this error. It's saying that a property is an array, but it needs an array. It seems to me like it has what it wants. This error is not intuitive. Can someone explain to me what the library wants?
The text was updated successfully, but these errors were encountered: