express.json([options])
The options object in the static function lets us to configure the content type on which the middleware will work. And the default media type is “application/json”.
Can anyone please help me to understand some cases wherein this content type needs to configure differently than the default one?
The reason for this question is that JSON.parse function which works under the hood of this middleware must have a valid JSON string as its input. While looking at the other possible content-types listed below (sample listing only), it seems none other than the default type can represent a valid JSON string.
Therefore does this configurable option for type, make sense ?
application/json
application/ld+json (JSON-LD)
application/msword (.doc)
application/pdf
application/sql
...
audio/mpeg
audio/ogg
image/avif
image/jpeg (.jpg, .jpeg, .jfif, .pjpeg, .pjp) [19]
image/png
image/svg+xml (.svg)
image/tiff (.tif)
model/obj (.obj)
multipart/form-data
text/plain
text/css
text/csv
text/html
text/javascript(.js)
text/xml