INNER CODE UNIT · JavaScript
createJsonParser
expressjs/body-parser · lib/types/json.js:71
function createJsonParser (options) {
const reviver = options?.reviver
const strict = options?.strict !== false
if (strict) {
return function parse (body) {
if (body.length === 0) {
// special-case empty json body, as it's a common client-side mistake
// TODO: maybe make this configurable or part of "strict" option
return {}
}
if (body[0] !== '{' && body[0] !== '[') {
const first = firstNonWhitespaceChar(body)
if (first !== '{' && first !== '[') {
debug('strict violation')
throw createStrictSyntaxError(body, first)
}