• Converts a JavaScript value to a JSON string, changing undefined properties in the JavaScript object to null properties in the JSON string.

    WARNING: null values will become undefined 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 retain null values, you should wrap them yourself in a string before using this function. Alternatively, you can write your own replacer that will preserve null in a way that you can recover later.

    Parameters

    • value: unknown

      A JavaScript value, usually an object or array, to be converted.

    • Optionalreplacer: (this: unknown, key: string, value: unknown) => unknown

      A function that transforms the results. Note that all undefined values returned by the replacer will be further transformed into null in the JSON string.

    • Optionalspace: string | number

      Adds 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.

    Returns string