As JSON2.9.0+

  1. moment.duration().toJSON();

When serializing a duration object to JSON, it will be represented as anISO8601 string.

  1. JSON.stringify({
  2. postDuration : moment.duration(5, 'm')
  3. }); // '{"postDuration":"PT5M"}'

Invalid durations return Invalid Date as json representation.