Skip to content

Commit 079415f

Browse files
author
Dmitry Dutikov
committed
Docs update
1 parent 0f47c04 commit 079415f

File tree

2 files changed

+73
-13
lines changed

2 files changed

+73
-13
lines changed

README.md

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,64 @@ console.log(typeof value.date, value.date.constructor.name); // => object Date
3535
console.log(typeof value.amount); // => bigint
3636
console.log(typeof value.debt, isNaN(value.debt)); // => number true
3737
```
38-
## Motivation
39-
JSON format is good enough for everyday usage. There are some libraries trying to introduce syntax to make JSON closer
40-
to modern JavaScript, some libraries trying to introduce functions serialization. All that is not important and is not
41-
required for everyday usage. However, there is one thing annoying me always - date values.
4238

43-
We are serializing dates a lot and each time we parse it back we are getting a string. As a result we have to deal with
44-
the Date constructor manually each time. Even if we are no need date as an object, date formatter will have to make date
45-
object in order to make user-friendly text representation. Otherwords we are forced to care about dates additionally.
46-
It produces bulky solutions or tons of inline type conversions.
39+
## Features
40+
* Can parse standard `JSON` format
41+
* Support for `BigInt` values
42+
* Support for `NaN` values
43+
* Support for `Infinity`/`-Infinity` values
44+
* Support for typed serialization/deserialization, work with `Date` class out of the box
45+
* Allow using trailing commas
46+
* Zero-dependency npm-package
47+
* Both CJS/ESM modules support
48+
49+
## Installation
50+
```shell
51+
npm install json22
52+
```
53+
In your code
54+
```javascript
55+
import { JSON22 } from 'json22'
4756

48-
But I'm lazy developer, I'll do everything to get rid of any additional careness.
57+
const data = { date: new Date() };
58+
const s = JSON22.stringify(data);
59+
```
60+
61+
For old-fashioned applications
62+
```javascript
63+
const { JSON22 } = require('json22');
64+
65+
const data = { date: new Date() };
66+
const s = JSON22.stringify(data);
67+
```
68+
69+
## Integration
70+
### Using with Express
71+
There is library [json22-express](https://github.com/dancecoder/json22-express) providing JSON22 support for expressjs applications
72+
```javascript
73+
import express from 'express';
74+
import { json22express } from 'json22-express'
75+
76+
const app = express();
77+
app.use(json22express());
78+
79+
app.get('/date', (req, res, next) => {
80+
res.status(200).json22({ date: new Date() });
81+
next();
82+
});
83+
```
84+
### Using with Axios
85+
There is library [json22-axios](https://github.com/dancecoder/json22-axios) providing JSON22 support for client applications
86+
```javascript
87+
import axios from 'axios';
88+
import { Json22RequestInterceptor } from 'json22-axios';
89+
90+
axios.interceptors.request.use(Json22RequestInterceptor());
91+
// interceptor allow you to send and receive JSON22
92+
```
4993

5094
## API
51-
Note: JSON22 cannot be used as drop in JSON object replacement due to `parse` and `stringify` methods
95+
Note: JSON22 cannot be used as drop in JSON object replacement due to `parse` and `stringify` methods
5296
arguments incompatibility. But you may not be worried in case you are using first arguments only.
5397
```typescript
5498
class JSON22 {
@@ -165,3 +209,15 @@ The JSON22 support for `toJSON` method of an object as well as JSON. In some cas
165209
and `toJSON` methods. Typical example is the Date class. The JSON22 at first is a solution to serialize/deserialize
166210
date values, so __`valueOf` have higher priority over `toJSON`__. This is also true for any object implementing `valueOf`
167211
and `toJSON` both.
212+
213+
## Motivation
214+
JSON format is good enough for everyday usage. There are some libraries trying to introduce syntax to make JSON closer
215+
to modern JavaScript, some libraries trying to introduce functions serialization. All that is not important and is not
216+
required for everyday usage. However, there is one thing annoying me always - date values.
217+
218+
We are serializing dates a lot and each time we parse it back we are getting a string. As a result we have to deal with
219+
the Date constructor manually each time. Even if we are no need date as an object, date formatter will have to make date
220+
object in order to make user-friendly text representation. Otherwords we are forced to care about dates additionally.
221+
It produces bulky solutions or tons of inline type conversions.
222+
223+
But I'm lazy developer, I'll do everything to get rid of any additional careness.

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"name": "json22",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "JSON superset with an ability to deal with classes and extended support for number values",
5-
"author": "Dmitry Dutikov",
5+
"author": {
6+
"email": "[email protected]",
7+
"name": "Dmitry Dutikov"
8+
},
69
"license": "MIT",
710
"keywords": [
811
"json",
@@ -12,7 +15,8 @@
1215
"BigInt",
1316
"types",
1417
"valueOf",
15-
"toJSON"
18+
"toJSON",
19+
"json22"
1620
],
1721
"repository": "github:dancecoder/json22",
1822
"main": "index.js",

0 commit comments

Comments
 (0)