# urlencode2json-middleware

> urlencode2json-middleware is a middleware to enhance express bodyparser to parse string to crrect json type.

Latest version **0.1.5** (published 2017-08-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install urlencode2json-middleware
pnpm add urlencode2json-middleware
yarn add urlencode2json-middleware
bun add urlencode2json-middleware
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2017-08-04 |
| First published | 2017-08-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 767196201@qq.com |
| Maintainers | juan.xu |

## Links

- npm: https://www.npmjs.com/package/urlencode2json-middleware
- npm.io page: https://npm.io/package/urlencode2json-middleware

## Dependencies (1)

- [debug](https://npm.io/package/debug.md) ^2.6.8

## Recent versions

- 0.1.5 (latest) — 2017-08-04
- 0.1.4 — 2017-08-03
- 0.1.3 — 2017-08-03

## README

[![Build Status](https://travis-ci.org/SusanXu123/urlencode2json-middleware.svg?branch=master)](https://travis-ci.org/SusanXu123/urlencode2json-middleware)  [![Coverage Status](https://coveralls.io/repos/github/SusanXu123/urlencode2json-middleware/badge.svg?branch=master)](https://coveralls.io/github/SusanXu123/urlencode2json-middleware?branch=master)



## Installation

```bash
$ npm install urlencode2json-middleware
```

## Usage

urlencode2json-middleware is a middleware to enhance express bodyparser to parse string to crrect json type.

Example _app.js_:

```js
const express = require('express')
const bodyParser = require('body-parser')
const urlencode2json = require('urlencode2json-middleware')

const app = express()
app.use(bodyParser.json()) // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
app.use(urlencode2json)
```

When a post request as below send to server
```bash
POST / HTTP/1.1
Host: ******
Content-Type: application/x-www-form-urlencoded

user=tobi&arg_bool=true&arg_number=3&arg_bool_str="true"&arg_number_str="33"&arg_null=null&arg_null_str="null"

```

By default, `bodyParser.urlencoded` can not distinguish `number`, `boolean`, `null` with `string`, and will parse data to `request.body` like below:
```js
request.body === {
  "user":"tobi",
  "arg_bool":"true",
  "arg_number":"3",
  "arg_bool_str":"true",
  "arg_number_str":"33",
  "arg_null":"null",
  "arg_null_str":"null",
}

```

This middleware will enhance `bodyParser.urlencoded` to paser default to correct primary type, and will paser data to `request.body` like below:

```js
request.body === {
  "user":"tobi",
  "arg_bool":true,
  "arg_number":3,
  "arg_bool_str":"true",
  "arg_number_str":"33",
  "arg_null":null,
  "arg_null_str":"null",
}

---
_Source: https://npm.io/package/urlencode2json-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
