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 6327085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:12:54+00:00 2026-05-24T17:12:54+00:00

Sorry if this is a stupid question, this is my first JS project… I’m

  • 0

Sorry if this is a stupid question, this is my first JS project…

I’m trying to deserialize a custom object in JS using JSON. The problem is, JSON.parse() does not return the object as its original type. Since directly casting the returned object to the desired type doesn’t seem possible, that leaves me with the ‘reviver’ option…

Am I missing something here? Wasn’t the entire point of JSON to avoid having to write custom methods to serialize and deserialize objects? What’s the point of using JSON if I have to write my own method ‘revive’ my 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-05-24T17:12:55+00:00Added an answer on May 24, 2026 at 5:12 pm

    JSON is a format for raw data. It’s very primitive. It supports dictionaries (aka. javascript objects, hashes, associative arrays), arrays, strings, numbers, booleans and null. That’s it. The reason it doesn’t do more is that those primitives are language agnostic, and nearly all programming language have built in tools to handle those types of data.

    If you had other notation like “class” then suddenly it becomes very bound to specific languages or codeboases, and lose it’s wide and generic applicability.

    So think of JSON as simple raw data. JSON is not instance marshalling or complete object serialization. So yes you need to write “revivers” if you intend to serialize JS objects instantiated from constructors.

    This is the approach things like backbone.js take:

    new Book({
      title: "One Thousand and One Nights",
      author: "Scheherazade"
    });
    

    You simply pass your plain object of data (the result of your JSON.parse()) to the call to your constructor of choice. From there you can do any number of things to read it’s values into your new object.

    Javascript has no standard way of Marshalling whole objects like you can in ruby with Marhsal.dump(obj) for instance.


    EDIT: One last major point…

    Javascript objects don’t have a “type” as you would think of it in other languages. A Javascript object is simply a a dictionary of key/value pairs. When you do something like new SomeClass() you get a new object, that has a special prototype property that points to the prototype property of the SomeClass function object. Wether an object is an instance of SomeClass is less of a clear cut question than you may think at first glance.

    Instead you may ask “What is my constructor function object?” or “What objects are in my prototype chain?”

    So if you wanted to convey “type” in JSON, which is stored as a string, then how would you store a reference to a prototype object? Maybe the prototype object is not named in the global scope at all, and only available via closure? Then when you write that out to string, you have no way of referencing that prototype object anymore at all.

    The point is that javascripts prototypical approach to object instantiation, combined with it’s closure based lexical scoping and the fact that objects hold their values more like C pointers than literal values, makes it very very hard to fully serialize an object out to a location external to the VM.

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

Sidebar

Related Questions

Sorry, this might be a basic/stupid/noob question - I am just trying to tweak
First of all I am sorry to ask a stupid question, this is because
Sorry if this is a stupid question, but I have come across a problem
Sorry if this is a stupid question, but I'm trying to learn ExtJS ;)
First of all, sorry if this might be a stupid question. I'm very new
Sorry if this is a stupid question... I've developed an application that creates absolute
Sorry if this sounds like a really stupid question, but I need to make
Sorry if this is a stupid question. I want to create an HTTP handler
Sorry for maybe this is stupid question, I just want download source code form
First of all I am sorry for the stupid question I am going to

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.