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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:33:27+00:00 2026-06-04T01:33:27+00:00

I am attempting to abuse a reviver function with JSON.parse. I basically want to

  • 0

I am attempting to abuse a reviver function with JSON.parse.

I basically want to make certain fields “null”.

If I do this:

var json_data = JSON.parse(j, function(key, value) {
  if (key == "name") {        
    return value;
  } else {
    return null;    
  }    
});

The entire json_data object ends up null. In fact, no matter what I make the else, that defines the value of the json_object.

Interestingly, this works as expected:

var json_data = JSON.parse(j, function(key, value) {
  if (key == "name") {        
    return "name";
  } else {
    return value;    
  }    
});

The property “name” now has a value of “name”.

JSON in question:

var j = '{"uuid":"62cfb2ec-9e43-11e1-abf2-70cd60fffe0e","count":1,"name":"Marvin","date":"2012-05-13T14:06:45+10:00"}';

Update

I just realized that the inverse of what I want to do works as well so I can nullify the name field:

var json_data = JSON.parse(j, function(key, value) {
  if (key == "name") {        
    return null;
  } else {
    return value;    
  }    
});
  • 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-04T01:33:28+00:00Added an answer on June 4, 2026 at 1:33 am

    Through some experimentation, it looks like a final call is made to the function where the key is an empty string and the value is the top-level object:

    > JSON.parse('{"hello": "world"}', function(k, v) { console.log(arguments); return v; })
    ["hello", "world"]
    ["", Object]
    

    So you could use:

    var json_data = JSON.parse(j, function(key, value) {
      if (key == "name" || key === "") {        
        return value;
      } else {
        return null;    
      }    
    });
    

    Now, since "" does appear to be a valid JSON key, to be 100% correct it might be better to use something like:

    var json_data;
    JSON.parse(j, function(key, value) {
      if (key == "name") {        
        return value;
      } else if (key === "") {
        json_data = value;
        return null;
      } else {
        return null;    
      }    
    });
    

    But that might be a little bit paranoid 😉

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

Sidebar

Related Questions

Attempting to use the data series from this example no longer passes the JSONLint
Attempting to make a NSObject called 'Person' that will hold the login details for
Attempting to follow this Java tutorial . About 63 pages in, you are instructed
Attempting to deserialize JSON data and update each object's prototype and inherit a common
Just attempting this question I found in a past exam paper so that I
Attempting to render a model object into a JSON structure via a partial, like
Attempting to get an answer to this question. How can I turn off the
attempting to use this railscast as a guide: http://railscasts.com/episodes/197-nested-model-form-part-2?view=asciicast and running into this error:
I was attempting to parse example.com's home page with xpath and cssselect but it
Attempting to run this SQL: DELIMITER $$ CREATE TRIGGER crypt_f BEFORE INSERT ON c_data_test

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.