Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 904 Bytes

preprocessForSerialization.md

File metadata and controls

23 lines (17 loc) · 904 Bytes

preprocessForSerialization (source code)

  • Curried: false
  • Failsafe status: failsafe by default

The preprocessForSerialization function creates a ready-to-be-serialized version of the given object by recursively traversing all the object properties and replacing them with their JSON serializable versions. This is particularly helpful when serializing objects that include non-serializable data types, such as Date objects, dayjs objects or custom classes.

Arguments:

  • object: The object to be JSON serialized.

Usage:

preprocessForSerialization(dayjs("1980-01-01")); // returns "1980-01-01T00:00:00.000Z"
preprocessForSerialization({
  toJSON: () => ({ firstName: "Oliver", lastName: "Smith" }),
}); // returns { firstName: "Oliver", lastName: "Smith" }