Skip to content

Commit 09624d5

Browse files
committed
Updated docs
1 parent 970d177 commit 09624d5

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ And nested ones, too.
7474
| `Date` | `string` via `toISOString()` |
7575
| `RegExp` | `string` |
7676

77-
#### Required
77+
#### Required
7878
You can set specific fields of an object as `required` in your schema, by adding `required: true` inside the key properties.
7979
Example:
8080
```javascript
@@ -94,6 +94,31 @@ const schema = {
9494
```
9595
If the object to stringify has not the required field(s), `fast-json-stringify` will throw an error.
9696

97+
#### Missing fields
98+
If a field *is present* in the schema (and is not required) but it *is not present* in the object to stringify, `fast-json-stringify` will not write it in the final string.
99+
Example:
100+
```javascript
101+
const stringify = fastJson({
102+
title: 'Example Schema',
103+
type: 'object',
104+
properties: {
105+
nickname: {
106+
type: 'string'
107+
},
108+
mail: {
109+
type: 'string',
110+
required: true
111+
}
112+
}
113+
})
114+
115+
const obj = {
116+
117+
}
118+
119+
console.log(stringify(obj)) // '{"mail":"[email protected]"}'
120+
```
121+
97122
## Acknowledgements
98123

99124
This project was kindly sponsored by [nearForm](http://nearform.com).

0 commit comments

Comments
 (0)