Skip to content

Commit 6c7f9a9

Browse files
allevodelvedor
authored andcommitted
Add default doc in README (#89)
1 parent 71d8f1e commit 6c7f9a9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,28 @@ const obj = {
163163
console.log(stringify(obj)) // '{"mail":"[email protected]"}'
164164
```
165165

166+
<a name="defaults"></a>
167+
#### Defaults
168+
`fast-json-stringify` supports `default` jsonschema key in order to serialize a value
169+
if it is `undefined` or not present.
170+
171+
Example:
172+
```javascript
173+
const stringify = fastJson({
174+
title: 'Example Schema',
175+
type: 'object',
176+
properties: {
177+
nickname: {
178+
type: 'string',
179+
default: 'the default string'
180+
}
181+
}
182+
})
183+
184+
console.log(stringify({})) // '{"nickname":"the default string"}'
185+
console.log(stringify({nickname: 'my-nickname'})) // '{"nickname":"my-nickname"}'
186+
```
187+
166188
<a name="patternProperties"></a>
167189
#### Pattern properties
168190
`fast-json-stringify` supports pattern properties as defined by JSON schema.

0 commit comments

Comments
 (0)