Return JSON when response is array

As described in #781, it makes sense to return JSON when an array is returned as response.