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
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.
112
+
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.
112
113
Example:
113
114
```javascript
114
115
constschema= {
@@ -129,7 +130,7 @@ If the object to stringify is missing the required field(s), `fast-json-stringif
129
130
130
131
<aname="missingFields"></a>
131
132
#### Missing fields
132
-
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.
133
+
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.
`fast-json-stringify` supports additional properties as defined by JSON schema.
215
-
*additionalProperties* must be an object or a boolean, declared in this way: `{ type: 'type' }`.
215
+
`fast-json-stringify` supports additional properties as defined by JSON schema.
216
+
*additionalProperties* must be an object or a boolean, declared in this way: `{ type: 'type' }`.
216
217
*additionalProperties* will work only for the properties that are not explicitly listed in the *properties* and *patternProperties* objects.
217
218
218
219
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>.
219
220
Missing fields are ignored to avoid having to rewrite objects before serializing. However, other schema rules would throw in similar situations.
220
-
If *additionalProperties* is set to `true`, it will be used by `JSON.stringify` to stringify the additional properties. If you want to achieve maximum performance, we strongly encourage you to use a fixed schema where possible.
221
+
If *additionalProperties* is set to `true`, it will be used by `JSON.stringify` to stringify the additional properties. If you want to achieve maximum performance, we strongly encourage you to use a fixed schema where possible.
221
222
Example:
222
223
```javascript
223
224
conststringify=fastJson({
@@ -327,8 +328,8 @@ console.log(stringify({
327
328
328
329
<a name="ref"></a>
329
330
#### Reuse - $ref
330
-
If you want to reuse a definition of a value, you can use the property `$ref`.
331
-
The value of `$ref` must be a string in [JSON Pointer](https://tools.ietf.org/html/rfc6901) format.
331
+
If you want to reuse a definition of a value, you can use the property `$ref`.
332
+
The value of `$ref` must be a string in [JSON Pointer](https://tools.ietf.org/html/rfc6901) format.
332
333
Example:
333
334
```javascript
334
335
constschema= {
@@ -364,7 +365,7 @@ const schema = {
364
365
365
366
conststringify=fastJson(schema)
366
367
```
367
-
If you need to use an external definition, you can pass it as an option to `fast-json-stringify`.
368
+
If you need to use an external definition, you can pass it as an option to `fast-json-stringify`.
368
369
Example:
369
370
```javascript
370
371
constschema= {
@@ -488,6 +489,16 @@ Otherwise, instead of raising an error, null values will be coerced as follows:
488
489
- `string` -> `""`
489
490
- `boolean` -> `false`
490
491
492
+
<a name="caveat"></a>
493
+
## Caveat
494
+
495
+
In order to achieve lowest cost/highest performance redaction `fast-json-stringify`
496
+
creates and compiles a function (using the `Function` constructor) on initialization.
497
+
While the `schema` is currently validated for any developer errors, it's recommended against
498
+
allowing user input to directly supply a schema.
499
+
It can't be guaranteed that allowing user input for the schema couldn't feasibly expose an attack
0 commit comments