Socket
Book a DemoInstallSign in
Socket

@body/json

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@body/json

Parse a JSON body of an incoming HTTP request.

latest
Source
npmnpm
Version
0.2.2
Version published
Weekly downloads
13
-35%
Maintainers
1
Weekly downloads
 
Created
Source

JSON body parser

Parse a JSON body of an incoming HTTP request.

Installation

npm install --save @body/json

Usage

const getJsonBody = require('@body/json')

// ...

app.post('/v1/users', async (req, res, next) => {
  try {
    const body = await getJsonBody(req)

    // ...
  } catch (err) {
    return next(err)
  }
})

// ...

API

getJsonBody(req: Request, options: Options): Promise<any>

Parse the body of the incoming request req. Returns a promise of the parsed body.

Options

inflate (boolean)

When set to true, then bodies with a deflate or gzip content-encoding will be inflated before being parsed.

Defaults to false.

strict (boolean)

When set to true, will only accept arrays and objects; when false will accept anything JSON.parse accepts.

Defaults to true.

FAQs

Package last updated on 21 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts