You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

json22-express

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json22-express

Expressjs middleware providing support to JSON22 data format in your applications

0.0.2
latest
Source
npmnpm
Version published
Weekly downloads
2
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

JSON22-Express

Expressjs middleware providing support to JSON22 data format in your applications.

Features

  • Ready to use Express middleware
  • Parse JSON22 body content
  • Parse JSON body content
  • Support for deflate, gzip, br content encodings
  • Define Request.json22 method to send JSON22 encoded data
  • Zero-dependency npm-package
  • Both CJS/ESM modules support

Installation

npm install json22-express

In your application initialization file add as a middleware

import express from 'express'; 
import { json22express } from 'json22-express'

const app = express();
app.use(json22express());

For old-fashioned applications

const express = require('express'); 
const { json22express } = require('json22-express'); 

const app = express();
app.use(json22express());

Configuration

JSON22-Express middleware support set of configuration options.

Pass options

import express from 'express'; 
import { json22express } from 'json22-express'

const app = express();
app.use(json22express({
    overrideResponseJsonMethod: true,
    maxContentLength: 1024 * 1024, // 1 meg
}));

Options

OptionTypeDefaultDescription
handleJsonbooleanfalseParse JSON content as well as JSON22
maxContentLengthnumberno limitPrevent from parsing of too large payloads
keepRawAsstringdo not keep raw bodyDefine Request field name to save payload Buffer to
overrideResponseJsonMethodbooleanfalseOverride response json method as well
json22ParseOptionsJson22ParseOptionsemptyOptions to be passed to JSON22.parse() method
json22StringifyOptionsJson22StringifyOptionsemptyOptions to be passed to JSON22.stringify() method

Usage

import express from 'express'; 
import { json22express } from 'json22-express'

const app = express();

app.use(json22express({
    overrideResponseJsonMethod: true,
    maxContentLength: 1024 * 1024, // 1 meg
}));

app.get('/date', (req, res, next) => {
    // Use .json22() method from Response object
    res.status(200).json22({ date: new Date() });
    next();
});

app.get('/json', (req, res, next) => {
    // in case overrideResponseJsonMethod is set to true you may use 
    // .json() method to send JSON22 as well
    res.status(200).json({ date: new Date() });
    next();
});

app.get('/deprecated', (req, res, next) => {
    // WARNING: don't do this. It is deprecated method interface and in case
    // you set overrideResponseJsonMethod to true this method will throw an exception
    res.json(200, { date: new Date() });
    next();
});


Keywords

json

FAQs

Package last updated on 06 Feb 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