Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:21:57+00:00 2026-06-17T20:21:57+00:00

I am trying to deserialize a json object that has a javascript date in

  • 0

I am trying to deserialize a json object that has a javascript date in it. When JSON.stringify is called on the object, dates are serialized to strings that are not properly deserialized back to dates. I have attempted to deserialize the object using both the native browser implementation with chrome, IE, and FF and using jquery. Both give the some results. Here is the snippet:

var obj = {Date: new Date()};
var objSer = JSON.stringify(obj);
var objDeser = JSON.parse(objSer);
var objJqDeser = $.parseJSON(objSer);

function getYear(value){
  try{
     return value.getYear();
  }
  catch(err){
    return err;
  }
}

$("#orig").text("Orig Year: " + getYear(obj.Date));
$("#deser").text("Deser Year: " + getYear(objDeser.Date));
$("#jqDeser").text("JqDeser Year: " + getYear(objJqDeser.Date));

I want objDeser.Date to be a js date not a string. You can see this problem in action here: http://jsbin.com/unijud/24/edit. Is there any js libraries that can properly deserialize the dates when building the javascript object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:21:59+00:00Added an answer on June 17, 2026 at 8:21 pm

    I took @LastCoder advice and wrote a simple implementation. It seems to be doing what I wanted it to.

    var jsonDates = {
      dtrx2: /\d{4}-\d{2}-\d{2}/,
      parse: function(obj){
          var parsedObj = JSON.parse(obj);
          return this.parseDates(parsedObj);
      },
      parseDates: function(obj){
        // iterate properties
        for(pName in obj){
    
          // make sure the property is 'truthy'
          if (obj[pName]){
            var value = obj[pName];
            // determine if the property is an array
            if (Array.isArray(value)){
              for(var ii = 0; ii < value.length; ii++){
                this.parseDates(value[ii]);
              }
            }
            // determine if the property is an object
            else if (typeof(value) == "object"){
              this.parseDates(value);
            }
            // determine if the property is a string containing a date
            else if (typeof(value) == "string" && this.dtrx2.test(value)){
              // parse and replace
              obj[pName] = new Date(obj[pName]);
            }
          }
        }
    
        return obj;
      }
    };
    

    A live example is available on jsbin. A reference is available on gist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to deserialize a Json object that I am getting from the
I'm trying to deserialize json to an object model where the collections are represented
I'm trying to use JSON.Net to deserialize a JSON object into a C# object.
I am trying to deserialize/map the below JSON to List<Bill > java object using
I'm trying to deserialize a piece of JSON to a C# object, with little
here's my problem: I'm trying to deserialize json that hasn't been done by me.
I am trying to deserialize a JSON string that looks like so: {'type':'clientlist','client_list':[]} I
I am trying to strongly type an object property that has been defined as
I am trying to deserialize a JSON string into a class instance in Haxe.
I am trying to serialize/deserialize JSON in Android using GSON. I have two classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.