• Skip to main content
  • Skip to search
  • Skip to select language
HTML

Structure of content on the web

  • Web APIs

    Interfaces for building web applications

  • Learn
    • CSS

      Learn to style content using CSS

    • Overview

      A customized MDN experience

    • FAQ

      Frequently asked questions about MDN Plus

  • HTTP Observatory

    Scan a website for free

  • JavaScript
  • Temporal.PlainDateTime
  • Temporal.PlainDateTime Experimental
  • Constructor
    1. Temporal.PlainDateTime() Experimental
  • Static methods
    1. compare() Experimental
    2. from() Experimental
  • Instance methods
    1. add() Experimental
    2. equals() Experimental
    3. round() Experimental
    4. since() Experimental
    5. subtract() Experimental
    6. toJSON() Experimental
    7. toLocaleString() Experimental
    8. toPlainDate() Experimental
    9. toPlainTime() Experimental
    10. toString() Experimental
    11. toZonedDateTime() Experimental
    12. until() Experimental
    13. valueOf() Experimental
    14. with() Experimental
    15. withCalendar() Experimental
    16. withPlainTime() Experimental
  • Instance properties
    1. calendarId Experimental
    2. day Experimental
    3. dayOfWeek Experimental
    4. dayOfYear Experimental
    5. daysInMonth Experimental
    6. daysInWeek Experimental
    7. daysInYear Experimental
    8. era Experimental
    9. eraYear Experimental
    10. hour Experimental
    11. inLeapYear Experimental
    12. microsecond Experimental
    13. millisecond Experimental
    14. minute Experimental
    15. month Experimental
    16. monthCode Experimental
    17. monthsInYear Experimental
    18. nanosecond Experimental
    19. second Experimental
    20. weekOfYear Experimental
    21. year Experimental
    22. yearOfWeek Experimental
  • Inheritance
  • call()
  • displayName Non-standard
  • arguments Non-standard Deprecated
  • caller Non-standard Deprecated
  • Instance methods
    1. __defineGetter__() Deprecated
    2. __defineSetter__() Deprecated
    3. __lookupGetter__() Deprecated
    4. __lookupSetter__() Deprecated
    5. toLocaleString()
    6. __proto__ Deprecated
    7. Temporal Experimental
    8. Temporal.Duration Experimental
    9. Temporal.Instant Experimental
    10. Temporal.Now Experimental
    11. Temporal.PlainDate Experimental
    12. Temporal.PlainMonthDay Experimental
    13. Temporal.PlainTime Experimental
    14. Temporal.PlainYearMonth Experimental
    15. Temporal.ZonedDateTime Experimental
  • In this article

    • Syntax
    • Description
    • Examples
    • Specifications
    • Browser compatibility
    • See also

    Temporal.PlainDateTime.prototype.toJSON()

    Limited availability

    This feature is not Baseline because it does not work in some of the most widely-used browsers.

    • experimental technology
      Check the Browser compatibility table carefully before using this in production.

    The toJSON() method of JSON.stringify().

    Syntax

    js
    toJSON()
    

    Parameters

    None.

    Return value

    A string representing the given date-time in the Temporal.PlainDateTime.from() function as the reviver of JSON.parse().

    Examples

    Using toJSON()

    js
    const dt = Temporal.PlainDateTime.from({ year: 2021, month: 8, day: 1 });
    const dtStr = dt.toJSON(); / '2021-08-01T00:00:00'
    const dt2 = Temporal.PlainDateTime.from(dtStr);
    

    JSON serialization and parsing

    This example shows how Temporal.PlainDateTime can be serialized as JSON without extra effort, and how to parse it back.

    js
    const dt = Temporal.PlainDateTime.from({ year: 2021, month: 8, day: 1 });
    const jsonStr = JSON.stringify({ nextBilling: dt }); / '{"nextBilling":"2021-08-01T00:00:00"}'
    const obj = JSON.parse(jsonStr, (key, value) => {
      if (key === "nextBilling") {
        return Temporal.PlainDateTime.from(value);
      }
      return value;
    });
    

    Specifications

    Specification
    Temporal
    # sec-temporal.plaindatetime.prototype.tojson

    Browser compatibility

    See also

    • Temporal.PlainDateTime
    • Temporal.PlainDateTime.from()
    • Temporal.PlainDateTime.prototype.toString()
    • Temporal.PlainDateTime.prototype.toLocaleString()

    Help improve MDN

    Temporal API allows you to work with dates, times, time zones, and durations. It is more powerful than the Date API.","name":"Temporal"}},"browserCompat":["javascript.builtins.Temporal.PlainDateTime.toJSON"],"pageType":"javascript-instance-method"}}

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant