Middleare component to send responses as JSON when requested as JSON