You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
__fast-json-stringify__ is two times faster than `JSON.stringify()`.
4
-
It is particularly suited if you are sending small JSON payloads, the
5
-
advantages reduces on large payloads.
3
+
__fast-json-stringify__ is significantly faster than `JSON.stringify()` for small payloads. Its performance advantage shrinks as your payload grows. It pairs well with [__flatstr__](https://www.npmjs.com/package/flatstr), which triggers a V8 optimization that improves performance when eventually converting the string to a `Buffer`.
6
4
7
5
Benchmarks:
8
6
@@ -119,7 +117,7 @@ And nested ones, too.
119
117
120
118
<aname="required"></a>
121
119
#### Required
122
-
You can set specific fields of an object as required in your schema, by adding the field name inside the `required` array in your schema.
120
+
You can set specific fields of an object as required in your schema by adding the field name inside the `required` array in your schema.
123
121
Example:
124
122
```javascript
125
123
constschema= {
@@ -136,7 +134,7 @@ const schema = {
136
134
required: ['mail']
137
135
}
138
136
```
139
-
If the object to stringify has not the required field(s), `fast-json-stringify` will throw an error.
137
+
If the object to stringify is missing the required field(s), `fast-json-stringify` will throw an error.
`fast-json-stringify` supports additional properties as defined inside JSON schema.
201
+
`fast-json-stringify` supports additional properties as defined by JSON schema.
204
202
*additionalProperties* must be an object or a boolean, declared in this way: `{ type: 'type' }`.
205
203
*additionalProperties* will work only for the properties that are not explicitly listed in the *properties* and *patternProperties* objects.
206
204
207
-
If *additionalProperties* is not present or is setted to false, every property that is not explicitly listed in the *properties* and *patternProperties* objects,will be ignored, as said in <ahref="#missingFields">Missing fields</a>.
208
-
If *additionalProperties* is setted to *true*, it will be used `fast-safe-stringify` to stringify the additional properties. If you want to achieve maximum performances we strongly encourage you to use a fixed schema where possible.
205
+
If *additionalProperties* is not present or is set to `false`, every property that is not explicitly listed in the *properties* and *patternProperties* objects,will be ignored, as described in <ahref="#missingFields">Missing fields</a>.
206
+
If *additionalProperties* is set to `true`, it will be used by `fast-safe-stringify` to stringify the additional properties. If you want to achieve maximum performance, we strongly encourage you to use a fixed schema where possible.
`fast-json-stringify` supports anyOf keyword as defined inside JSON schema. *anyOf* must be an array of valid JSON schemas. The differents schemas will be tried in this order so `stringify`will be slower the farest the right type is from the start of the array.
244
+
`fast-json-stringify` supports the anyOf keyword as defined by JSON schema. *anyOf* must be an array of valid JSON schemas. The different schemas will be tested in the specified order. The more schemas `stringify`has to try before finding a match, the slower it will be.
247
245
248
-
*anyOf* uses [ajv](https://www.npmjs.com/package/ajv) as a JSON schema validator to find the schema that match the data and this has an impact on performances. Use it only as a last resort.
246
+
*anyOf* uses [ajv](https://www.npmjs.com/package/ajv) as a JSON schema validator to find the schema that matches the data. This has an impact on performance—only use it as a last resort.
249
247
250
248
Example:
251
249
```javascript
@@ -264,7 +262,7 @@ const stringify = fastJson({
264
262
}
265
263
```
266
264
267
-
This schema will accept a string or a boolean for the property `undecidedType`. If no schema match the data, it will be stringified as `null`.
265
+
This schema will accept a string or a boolean for the property `undecidedType`. If no schema matches the data, it will be stringified as `null`.
If you want to squeeze a little bit more performance out of the serialisation, at the cost of readability in the generated code, you can pass `uglify:true` as an option.
375
-
Note that you have to manually install `uglify-es` in order for it to work. Only version 3 is supported.
372
+
If you want to squeeze a little bit more performance out of the serialization at the cost of readability in the generated code, you can pass `uglify:true` as an option.
373
+
Note that you have to manually install `uglify-es` in order for this to work. Only version 3 is supported.
376
374
Example:
377
375
378
376
Note that if you are using Node 8.3.0 or newer, there are no performance gains from using Uglify. See https://www.nearform.com/blog/node-js-is-getting-a-new-v8-with-turbofan/
0 commit comments