Skip to content

Commit fef21f9

Browse files
committed
Updated docs
1 parent eda6a31 commit fef21f9

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

README.md

-34
Original file line numberDiff line numberDiff line change
@@ -153,40 +153,6 @@ const obj = {
153153

154154
console.log(stringify(obj)) // '{"nickname":"nick","matchfoo":"42","otherfoo":"str","matchnum":3}'
155155
```
156-
`Object` and `Array` will be stringified as `{}` and `[]`.
157-
Since `fast-json-stringify` is faster than `JSON.stringify` because works on a **fixed schema**, we strongly advice you to not pass complex objects or array as object values, but decompose them in their individual properties and stringify them.
158-
```javascript
159-
const stringifyMe = {
160-
obj: {
161-
filed1: 'str',
162-
field2: 42
163-
}
164-
}
165-
// Not correct
166-
const stringify = fastJson({
167-
title: 'Example Schema',
168-
type: 'object',
169-
properties: {
170-
obj: {
171-
type: 'object'
172-
}
173-
}
174-
})
175-
176-
// Correct
177-
const stringify = fastJson({
178-
title: 'Example Schema',
179-
type: 'object',
180-
properties: {
181-
field1: {
182-
type: 'string'
183-
},
184-
field2: {
185-
type: 'number'
186-
}
187-
}
188-
})
189-
```
190156

191157
## Acknowledgements
192158

example.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ const stringify = fastJson({
2020
},
2121
reg: {
2222
type: 'string'
23+
},
24+
obj: {
25+
type: 'object',
26+
properties: {
27+
bool: {
28+
type: 'boolean'
29+
}
30+
}
31+
},
32+
arr: {
33+
type: 'array',
34+
items: {
35+
type: 'object',
36+
properties: {
37+
str: {
38+
type: 'string'
39+
}
40+
}
41+
}
2342
}
2443
},
2544
required: ['now'],
@@ -42,5 +61,7 @@ console.log(stringify({
4261
foo: 'hello',
4362
numfoo: 42,
4463
test: 42,
45-
strtest: '23'
64+
strtest: '23',
65+
arr: [{ str: 'stark' }, { str: 'lannister' }],
66+
obj: { bool: true }
4667
}))

0 commit comments

Comments
 (0)