Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
Is there a way to not include methods when converting an object to a json?

Right now, I'm trying to convert a object to a json, but the object has methods in it.

One common solution I've found is storing the function in the json, but that wouldn't work for me (mainly because that would totally break updating)

I think it will be easier to reinitialize the function every time the program is reloaded. What would be the best way to exclude functions when stringifying to json, but including the functions when the json is parsed?

Extra note: some of the functions are stored in arrays and other objects

Edit: Current code to load json data:

var loadData = JSON.parse(window.localStorage.getItem("slotAuto"));
G = {
    ...G,
    ...loadData
};

Current code to save json data:

var toSave = JSON.stringify(G, G.ReplaceNull);
console.log(toSave);
window.localStorage.setItem("saveGame", toSave);

Replace Null function:

if (value == null) {
    return undefined;
};
return value

Example object:

{
    functionList: [function () {
        console.log("do something")
    }]
}

Example output:

{
    "functionList": [null]
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!