-2
for(String objectName : jsonMap.keySet()){
            // List<map<String,String>> listObjects=jsonMap.get(objectName);
            List<Map <String, String>> jsonFieldMapToUpper= new List<Map<String, String>>();
            for(map<String,String> JsonFieldMap: jsonMap.get(objectName)){
                Map<String, String> keyVal=new Map<String, String>();
                for(String key : JsonFieldMap.keySet()){
                    keyVal.put(key.toUpperCase(), JsonFieldMap.get(key));
                    
                }
                jsonFieldMapToUpper.add(keyVal);
                jsonMap.put(objectName, jsonFieldMapToUpper);
            }
        }
        System.debug('TRANSFORMED '+jsonMap);
2
  • 2
    Welcome to the site. You need to make this into a question. At the moment it's just a block of code. From the title of the post we might get some idea, but in this case I don't think it matches what's in the body.
    – Dave
    May 4 at 9:00
  • 1
    @ABC, I think you misunderstand how this site works. Please take some time to take a Tour of the site, as well as reviewing the Help center to get a better understanding.
    – glls
    May 4 at 12:25
1

As David and I have said before, nested loops are not always bad. If one is traversing a complicated JSON-based hierarchy of values, it is incredibly common to use multiple nested or recursive loops to parse this kind of data. You still need three loops, ultimately, and three loops in sequence will take just as long as three nested loops, yet be slightly more complicated to write. Your current solution is considered a "correct" one.

Not the answer you're looking for? Browse other questions tagged or ask your own question.