For a standard JSON service, the content type is expected to be application/json
(see What is the correct JSON content type?).
Since null
, 123
or "foo"
are valid JSON documents, any service producing application/json
is alowed to return one of those as body.
What if I want to ensure that a service will return a valid JSON object or a valid JSON array?
Examples of valid objects
{}
or
{
"foo": "bar"
}
Examples of invalid objects
123
or
null
or
[
{ "foo": "bar" }
]
(this one would be a valid array)