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

153
Views
Is there a Java equivalent of Javascript's JSON.parse reviver function that I can use to transform a value during when parsing

I am looking for a way to transform a value during parse.

I have base64 encoded content inside a json formatted string with dynamic keys.

{
    "key0": "irrelevant",
    "key1": "VXNlbGVzcyBiYXNlNjQgY29udGVudA==",
    "key2": "QW5vdGhlciBVc2VsZXNzIGJhc2U2NCBjb250ZW50",
    "key3": {
        "key4": "b25lIG1vcmUgVXNlbGVzcyBiYXNlNjQgY29udGVudA==",
        "key5": "irrelevant",
        "key6": {
            "key7": "b25lIG1vcmUgdXNlbGVzcyBiYXNlNjQgc3RyaW5n",
            "key8": "dXNlbGVzcyBiYXNlNjQgc3RyaW5n",
            "key9": "TGFzdCB1c2VsZXNzIGJhc2U2NCBzdHJpbmcsIGJ1dCB0aGVyZSBjb3VsZCBiZSBtb3Jl"
        }
    }
}

I would like to replace the base64 content with a string and end up with something like this:

{
    "key0": "irrelevant",
    "key1": "replaced base64",
    "key2": "replaced base64",
    "key3": {
        "key4": "replaced base64",
        "key5": "irrelevant",
        "key6": {
            "key7": "replaced base64",
            "key8": "replaced base64",
            "key9": "replaced base64"
        }
    }
}

Javascript's JSON.parse method has the concept of a reviver function. Which I am aware that a "reviver" is a Javascript concept, however I am looking for something similar in Java. Here is an example of how it works on Javascript.

  1. https://stackoverflow.com/a/24374222/6076761
  2. https://stackoverflow.com/a/44911097

I am currently using Gson to parse the string to JsonElement.

NB: I do not have any information about the class type for this json string.

I know I could potentially parse the string to JsonObject and then possibly check for these strings recursively after.

However if someone knows of a way that I can do this during parse, please assist.

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!