# json_xml

> 1.xml to json; 2.json to xml; 3.express middleware

Latest version **1.2.5** (published 2018-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install json_xml
pnpm add json_xml
yarn add json_xml
bun add json_xml
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.5 |
| Published | 2018-03-20 |
| First published | 2017-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | elss-zion |
| Maintainers | elss-zion |
| Keywords | xml2json, json2xml, xml, json |

## Links

- npm: https://www.npmjs.com/package/json_xml
- Repository: https://github.com/ELSS-ZION/json_xml-for-node
- Homepage: https://github.com/ELSS-ZION/json_xml-for-node#readme
- Issues: https://github.com/ELSS-ZION/json_xml-for-node/issues
- npm.io page: https://npm.io/package/json_xml

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.2.5 (latest) — 2018-03-20
- 1.2.4 — 2017-09-28
- 1.2.3 — 2017-09-28
- 1.2.2 — 2017-09-20
- 1.2.1 — 2017-09-20
- 1.2.0 — 2017-09-20
- 1.1.0 — 2017-09-20
- 1.0.4 — 2017-09-20
- 1.0.3 — 2017-09-20
- 1.0.2 — 2017-09-20
- 1.0.1 — 2017-09-20
- 1.0.0 — 2017-09-20

## README

# json_xml

  + XML to JSON
  + JSON to XML
  + express middleware( req.body: JSON, req.rawBody: XML )

---
## XML to JSON

```js
const json_xml = require('json_xml')
var jsonObj = json_xml.xml2json(xmlStr)
```
### TYPE 1
``` xml
<xml>
  <appid>wx2421b1c4370ec43b</appid>
  <attach><![CDATA[attach1]]></attach>
  <attach>attach2</attach>
  <bank_type>1</bank_type>
  <sign></sign>
  <fee_type><is_subscribe><![CDATA[Y]]></is_subscribe></fee_type>
</xml>
```
``` js
{ xml:
   { appid: 'wx2421b1c4370ec43b',
     attach: [ 'attach1', 'attach2' ],
     bank_type: '1',
     sign: '',
     fee_type: { is_subscribe: 'Y' } } }
```
### TYPE 2
``` xml
<?xml version="1.0" encoding="utf-8"?>
<ROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="JobSendedDescription">
  <RetCode>Sucess</RetCode>
  <JobID>159142093</JobID>
  <OKPhoneCounts>1</OKPhoneCounts>
  <StockReduced>1</StockReduced>
  <ErrPhones />
</ROOT>
```
``` js
{ ROOT:
   { RetCode: 'Sucess',
     JobID: '159142093',
     OKPhoneCounts: '1',
     StockReduced: '1',
     ErrPhones: '' } }
```
---
## JSON to XML
```js
const json_xml = require('json_xml')
var jsonObj = json_xml.xml2json(jsonObj)
```
``` js
{ xml:
   { appid: 'wx2421b1c4370ec43b',
     attach: [ 'attach1', 'attach2' ],
     bank_type: '1',
     sign: '',
     fee_type: { is_subscribe: 'Y' } } }
```

``` xml
<xml>
  <appid><![CDATA[wx2421b1c4370ec43b]]></appid>
  <attach><![CDATA[attach1]]></attach>
  <attach><![CDATA[attach2]]></attach>
  <bank_type><![CDATA[1]]></bank_type>
  <sign><![CDATA[]]></sign>
  <fee_type>
    <is_subscribe><![CDATA[Y]]></is_subscribe>
  </fee_type>
</xml>
```

---
## As Middleware
```js
const express = require('express')
const app = express()
const app = express()

app.use(json_xml.middleware)
app.post('/', (req, res) => {
    console.log(req.rawBody) // XML
    console.log(req.body) // JSON
    res.send('success')
})
```

---
## Examples
+ [json_xml examples](https://github.com/ELSS-ZION/json_xml-for-node/tree/master/examples)

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