A JavaScript value, usually an object or array, to be converted.
Optional
replacer: (this: unknown, key: string, value: unknown) => unknownA function that transforms the results. Note that all undefined
values returned
by the replacer will be further transformed into null
in the JSON string.
Optional
space: string | numberAdds indentation, white space, and line break characters to the return-value JSON
text to make it easier to read. See the space
parameter of JSON.stringify
for more
details.
Converts a JavaScript value to a JSON string, changing
undefined
properties in the JavaScript object tonull
properties in the JSON string.WARNING:
null
values will becomeundefined
values after passing through serialize then deserialize. For example,{ a: 1, b: undefined, c: null }
will become{ a: 1, b: undefined, c: undefined }
. If you are passing around user data that needs to retainnull
values, you should wrap them yourself in a string before using this function. Alternatively, you can write your own replacer that will preservenull
in a way that you can recover later.