# waft-json

> ``` npm install waft-json

Latest version **1.1.15** (published 2022-01-12) · 0 weekly downloads

## Install

```sh
npm install waft-json
pnpm add waft-json
yarn add waft-json
bun add waft-json
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.15 |
| Published | 2022-01-12 |
| First published | 2021-04-25 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | yaozhi.szw, aligenie-skill |

## Links

- npm: https://www.npmjs.com/package/waft-json
- npm.io page: https://npm.io/package/waft-json

## Recent versions

- 1.1.15 (latest) — 2022-01-12
- 1.1.7 (beta) — 2021-06-16
- 1.1.13 — 2021-11-10
- 1.1.12 — 2021-09-07
- 1.1.11 — 2021-07-15
- 1.1.10 — 2021-07-01
- 1.1.8 — 2021-06-17
- 1.1.6 — 2021-05-07
- 1.1.5 — 2021-04-25
- 1.1.4 — 2021-04-25

## README

# Install

```
npm install waft-json

```

# Usage

## JSON.parse   string -> JSON.JSONObject

```ts
const jsonStr = '{"姓名":"小王","年龄":18,"身高":178.2}'
const obj2 = JSON.parseObject(jsonStr);
log('----> jsonStr parse:' + obj2.toString())
if(!obj2.has('体重')){
  log('----> 体重不存在')
}
const name = obj2.getString('姓名').toString();
const age = obj2.getInteger('年龄').intValue();
const height = obj2.getFloat('身高').floatValue();
log('----> jsonStr parse split:' + name + ' ' + age.toString() + ' ' + height.toString());
```

## JSON.JSONArray -> string

```ts
const arr = new JSONArray();
arr.push(obj);
arr.push('一串普通的字符串');
arr.push(3.2);
arr.push(3);
log('----> arr to string:' + arr.toString())

```

## JSON.JSONObject -> string

```ts
const obj = new JSONObject();
obj.set('name', '精灵');
obj.set('desc', '一串描述');
obj.set('age', 3);
obj.set('height', 155.3);

log('----> obj to string:' + obj.toString())
```

```ts
// 放字符串
const case1 = ["123", "456"];
expect(JSON.stringify(case1) == '["123","456"]');
// 放数字
const case2 = [123, 456];
expect(JSON.stringify(case2) == '[123,456]');
// 放对象
const stu:Student = {name:'小明'};
const stus = [stu];
expect(JSON.stringify(stus) == '[{}]');
// 放JSONValue
const obj =  new JSONObject();
obj.set("name","小明");
expect(JSON.stringify(obj) == '{"name":"小明"}');
// Array放JSONValue
const arr = [obj];
expect(JSON.stringify(arr) == '[{"name":"小明"}]');
// JSONArray放JSONValue
const json_arr = new JSONArray();
json_arr.push(obj);
expect(JSON.stringify(json_arr) == '[{"name":"小明"}]');
```

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