MCPcopy Create free account
hub / github.com/expressjs/body-parser / parse

Function parse

lib/types/json.js:74–99  ·  view source on GitHub ↗
(body)

Source from the content-addressed store, hash-verified

72 : type
73
74 function parse (body) {
75 if (body.length === 0) {
76 // special-case empty json body, as it's a common client-side mistake
77 // TODO: maybe make this configurable or part of "strict" option
78 return {}
79 }
80
81 if (strict) {
82 var first = firstchar(body)
83
84 if (first !== '{' && first !== '[') {
85 debug('strict violation')
86 throw createStrictSyntaxError(body, first)
87 }
88 }
89
90 try {
91 debug('parse json')
92 return JSON.parse(body, reviver)
93 } catch (e) {
94 throw normalizeJsonSyntaxError(e, {
95 message: e.message,
96 stack: e.stack
97 })
98 }
99 }
100
101 return function jsonParser (req, res, next) {
102 if (req._body) {

Callers

nothing calls this directly

Calls 3

firstcharFunction · 0.85
createStrictSyntaxErrorFunction · 0.85
normalizeJsonSyntaxErrorFunction · 0.85

Tested by

no test coverage detected