RestContext.response.responseBody = Blob.valueOf(JSON.serialize(locations));

JSON can handle almost any data type, including maps that include serializable types. The exceptions to this rule are items that can't be serialized, like SavePoint, SObjectField and so on.

Answer from sfdcfox on Stack Exchange
🌐
Michael Soriano
michaelsoriano.com › home › blog › a few apex tips that i’ve picked up along the way
A few Apex tips that I've picked up along the way - Michael Soriano
April 23, 2022 - Also, for objects, make sure you convert them all to strings by using JSON.serialize(). So sometimes you just want to get mock data from a flat file. Maybe you don’t want to store it in a table just yet. Or maybe you’re just quickly doing a prototype. This technique grabs the contents of a static resource through Apex, and optionally return it to the front end.
Discussions

apex - How to convert Map<String,Object> into Map<string,string>()? - Salesforce Stack Exchange
Stack Exchange network consists of 184 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI ... More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
April 1, 2016
Apex Map<String,Object> need to get object values - Salesforce Stack Exchange
Are you able to quickly explain how you would convert the map to string to prevent further issues? More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
Feed Item Detail | Salesforce Trailblazer Community
Skip to main content · The online Trailblazer Community becomes read-only Oct 30, 2026, as we move new community conversations to Slack. Read the FAQ More on developer.salesforce.com
🌐 developer.salesforce.com
March 29, 2019
visualforce - Convert JSON string into apex map - Salesforce Stack Exchange
How to convert this JSON text into apex map like Map> More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
June 27, 2018
🌐
YouTube
youtube.com › salesforce developers
Using Apex Maps with IDs and Strings | Interchange - YouTube
Can you interchange IDs and String in Apex maps? Check this Interchange session out to find out!Connect with Salesforce Developers:Website: https://www.devel...
Published: July 30, 2021
Views: 2K
🌐
Salesforce
trailhead.salesforce.com › trailblazer-community › feed › 0D54V00007T46eKSAR
Convert object values into | Salesforce Trailblazer Community
Skip to main content · Bring your team and maximize your impact at Dreamforce. Register three or more to unlock $999 passes
🌐
Deepika Khanna
mytutorialrack.com › home › understanding map methods in apex: key concepts and best practices
Understanding Map Methods in Apex: Key Concepts and Best Practices
June 1, 2023 - Map<String, Integer> studentScores ... mapSize = studentScores.size(); System.debug('mapSize '+mapSize); In Apex, the toString() method is used to convert a Map object into a String representation....
Find elsewhere
🌐
Propicsignifi
propicsignifi.github.io › mapper-apex › docs › Mapping
Mapping - Mapper.apex
In the code above, we add one field mapper to the mapper. This field mapper will get the field value of 'Name' from the source object, and use R.identity to process the value, and then set the final value to the fielf of name of the converted object.
🌐
Levelupsalesforce
levelupsalesforce.com › convert-map-to-list
Apex Convert Map To List - LevelUpSalesforce
August 30, 2022 - To loop over map values in Apex we can also use the Map.values() method. Sometimes there is no need to convert the map to a list. In the example below we collect all of the Account names by looping over the List of Accounts contained in the Map. 1//Running a query to grab some sample accounts ...
🌐
Salesforce
trailhead.salesforce.com › trailblazer-community › feed › 0D54S00000NDimwSAD
convert map<string,object> to list<case> - Trailhead - Salesforce
January 5, 2023 - Skip to main content · Bring your team and maximize your impact at Dreamforce. Register three or more to unlock $999 passes
🌐
Salesforce Developers
developer.salesforce.com › forums
Feed Item Detail | Salesforce Trailblazer Community
March 29, 2019 - Skip to main content · The online Trailblazer Community becomes read-only Oct 30, 2026, as we move new community conversations to Slack. Read the FAQ
Top answer
1 of 2
1

You cant convert the map to a list without an id. Alternatively why to convert it to List. Use the map itself. Below is a code example of how you can use it using your JSON response. For example, I want to insert this JSON response into the contact record, so I can map it using the MAP itself.:

@RestResource(urlMapping='/URIId/*') global class OwneriCRM {

@HttpPut
global static String UpdateOwnerinfo(){
    RestRequest req= RestContext.request;
    RestResponse res= RestContext.response;
    res.addHeader('Content-type','application/JSON');
    Map<String,Object> responseresult=new Map<String,Object>();
    Map<String,Object> results= (Map<String,Object>)JSON.deserializeUntyped(req.requestBody.toString());
     List<contact> insertList = new List<contact>();
    
    for (String key : results.keySet()){
    System.debug(results.get(key));
    contact c= new contact();
    c.ContactField__C = results.get(id);
    c.ContactField1__C = results.get(city);
    c.ContactField2__C = results.get(conference);
    c.ContactField3__C = results.get(division);
    c.ContactField3__C = results.get(full_name);
    c.ContactField3__C = results.get(name);
    insertList.add(c);
    
    }
    if(!insertList.Isempty()){
        update insertList;
    }
2 of 2
0

Question can be disregarded. Not sure if there is a way to withdraw the question.

Question was based on the fact that previous APIs had been sent in the following format:

{"data": {"more stuff": "stuff"} }

And the map key was 'data' with a list. In this scenario, the whole API was a list and the keys to the map were set in place with the actual values instead.

🌐
HIC GLOBAL SOLUTIONS
hicglobalsolutions.com › home › how to construct a json structure in maps using apex?
Know How To Construct JSON Structure In Maps Using Apex ?
October 3, 2024 - Construct JSON structure in maps helps yout to show data simply and efficiently with the details of an object the way you’ve always wanted it.
🌐
Stack Overflow
stackoverflow.com › questions › 73773910 › how-to-display-values-of-listmapstring-object-by-using-apexpageblocktable
salesforce - How to display values of List<Map<String, Object>> by using <apex:pageBlockTable>? - Stack Overflow
1 Retrieve the value<List> from the Map and store the each value in the String variable ... 0 Display a list of map in an apex:datatable with map key as column header and map values as row values
🌐
GitHub
gist.github.com › superfell › 1287653
deserialize json to map with Apex · GitHub
deserialize json to map with Apex · Raw · gistfile1.txt · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
Salesforce
trailhead.salesforce.com › trailblazer-community › feed › 0D54V00007T4IIBSA3
covert Map<String,Object> to | Salesforce Trailblazer Community
February 24, 2015 - Skip to main content · The online Trailblazer Community becomes read-only Oct 30, 2026, as we move new community conversations to Slack. Read the FAQ