@@ -77,8 +77,17 @@ Object with the following properties.
7777_ Type_ : ` number ` \
7878_ Default_ : ` Number.POSITIVE_INFINITY ` (no maximum size)
7979
80- Maximum ` JSON.stringify(value).length ` . Additional properties beyond the size
81- limit [ are omitted] ( #big-output ) .
80+ Big JSON strings can make a process, filesystem operation or network request
81+ crash. ` maxSize ` prevents it by setting a maximum
82+ ` JSON.stringify(value).length ` .
83+
84+ Additional properties beyond the size limit [ are omitted] ( #big-output ) . They are
85+ completely removed, not truncated (including strings).
86+
87+ ``` js
88+ const input = { one: true , two: ' a' .repeat (1e6 ) }
89+ JSON .stringify (safeJsonValue (input, { maxSize: 1e5 }).value ) // '{"one":true}"
90+ ```
8291
8392### Return value
8493
@@ -134,7 +143,8 @@ _Type_: `string`
134143Reason for the change among:
135144
136145- [ Exceptions] ( #exceptions ) : [ ` "unsafeCycle" ` ] ( #cycles ) ,
137- [ ` "unsafeException" ` ] ( #infinite-recursion ) , [ ` "unsafeBigInt" ` ] ( #bigint ) ,
146+ [ ` "unsafeBigInt" ` ] ( #bigint ) , [ ` "unsafeSize" ` ] ( #big-output ) ,
147+ [ ` "unsafeException" ` ] ( #infinite-recursion ) ,
138148 [ ` "unsafeToJSON" ` ] ( #exceptions-in-tojson ) ,
139149 [ ` "unsafeGetter" ` ] ( #exceptions-in-getters )
140150- [ Invalid descriptors] ( #invalid-descriptors ) :
@@ -149,7 +159,6 @@ Reason for the change among:
149159 [ ` "ignoredArrayProperty" ` ] ( #array-properties )
150160- [ Unresolved values] ( #unresolved-values ) : [ ` "unresolvedToJSON" ` ] ( #tojson ) ,
151161 [ ` "unresolvedClass" ` ] ( #classes ) , [ ` "unresolvedGetter" ` ] ( #getters )
152- - [ Big output] ( #big-output ) : [ ` "unsafeSize" ` ] ( #big-output )
153162
154163##### changes[ * ] .error
155164
@@ -195,6 +204,14 @@ JSON.stringify(input) // Throws due to BigInt
195204JSON .stringify (safeJsonValue (input).value ) // '{"one":true}"
196205```
197206
207+ ### Big output
208+
209+ ``` js
210+ const input = { one: true , two: ' \n ' .repeat (5e8 ) }
211+ JSON .stringify (input) // Throws due to max string length
212+ JSON .stringify (safeJsonValue (input).value ) // '{"one":true}"
213+ ```
214+
198215### Exceptions in ` toJSON() `
199216
200217``` js
@@ -440,19 +457,6 @@ JSON.parse(JSON.stringify(input)) // { one: true }
440457safeJsonValue (input).value // { one: true }
441458```
442459
443- ## Big output
444-
445- Big JSON strings can make a process, filesystem operation or network request
446- crash.
447-
448- When using the [ ` maxSize ` option] ( #maxsize ) , properties that are too large are
449- omitted. Large values (including strings) are completely removed, not truncated.
450-
451- ``` js
452- const input = { one: true , two: ' a' .repeat (1e6 ) }
453- JSON .stringify (safeJsonValue (input, { maxSize: 1e5 }).value ) // '{"one":true}"
454- ```
455-
456460# Support
457461
458462For any question, _ don't hesitate_ to [ submit an issue on GitHub] ( ../../issues ) .
0 commit comments