3
Follows json (has only 1 error, may have several errors):
{
"errors": [
{
"code": "XX-55",
"path": "customer.id",
"description": "Cliente não encontrado"
}
]
}
Another example of the return: (Several errors)
{
"errors": [
{
"code": "XD-011",
"path": "items[0].product",
"description": "Informe o nome do produto"
},
{
"path": "items[0].quantity",
"description": "must be between 1 and 999999"
},
{
"code": "BJ-009",
"path": "items[0].price",
"description": "Todos os valores devem ser maiores que zero"
}
]
}
How can I know if the schema is of this format ? Because the return code may be different from the above json code. What interests me is the json code above.
I’m using JsonConvert.DeserializeObject
to convert, but the schemma may be different. How can I know in the string has this format: errors, code, path and Description ?
Can you tell from the beginning
schema
is structured? That is, it has, somewhere in its code, the definition ofschema
?– João Martins
@Joãomartins No, it just returns like this:
{"errors":[{"code":"XX-55","path":"customer.id","description":"Cliente não encontrado"}]}
– Matheus Miranda
You have a library ready for this: https://www.newtonsoft.com/jsonschema
– Matheus Miranda
I just can’t make it work :/
– Matheus Miranda
Okay, this library was going to tell you to test it, but for that you have to know the structure of
schema
before it can validate it.– João Martins
@Joãomartins worse than it doesn’t have, only that code above it.
– Matheus Miranda
@Joãomartins this does not serve: https://www.liquid-technologies.com/online-json-to-schema-converter ?
– Matheus Miranda
It works, but it’s a converter online. You would have to include something like this in your application. You can receive any
schema
? And you don’t know how many or which ones before, right?– João Martins
@Maybe there is another way to do this without using this library, or without knowing the schema structure. Only that code above Json that returns me. I don’t know how many or which before.
– Matheus Miranda