This looks like a job for $.map!

var data = {
    "category": [{
          "id": 28,
          "name": "Dogs"
      },
      {
          "id": 14,
          "name": "Cats"
      },
      {
          "id": 878,
          "name": "Sheep"
      }]
}

var cats = $.map(data.category, function(v){
    return v.name;
}).join(', ');
Answer from gen_Eric on Stack Overflow
🌐
Make Community
community.make.com › questions
How to combine multipe JSON Strings? - Questions - Make Community
August 5, 2024 - Hello Community, I’m feeling quite frustrated right now. For about two hours, I’ve been trying to merge two or more JSON strings into one. Here’s what I’ve done so far: I receive a response from OpenAI and convert that response into structured data. Then, I aggregate a dataset using JSON Aggregate to create a JSON string.
Discussions

text processing - How to combine strings from JSON values, keeping only part of the string? - Unix & Linux Stack Exchange
You don't parse JSON with sed. JSON is a structured document format unsuitable for parsing by anything other than a JSON parser. Doing it with sed would require you to implement a JSON parser in sed that could handle the different entity encoding etc. More on unix.stackexchange.com
🌐 unix.stackexchange.com
November 29, 2018
How to concatenate json or string outputs from two nodes
Hi, I want to produce a single JSON file with two key-value pairs. I have two database views which I have used in ‘DB Query Reader’ nodes and then I am converting two outputs to two different Json using ‘Table to Json’ node. Now I want to concatenate these two Json as two key-value ... More on forum.knime.com
🌐 forum.knime.com
0
0
December 24, 2019
How to concatenate JSON data into string?
This assumes your JSON data is held in a variable named json which we've passed into the parse() method. More on stackoverflow.com
🌐 stackoverflow.com
mysql - Join all JSON object string values - Stack Overflow
In a MySQL 8 JSON column I have a JSON object with values of different types (but with no nested objects). Like this: { "abc": "Something123", "foo": 63.4, ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
JSONata
docs.jsonata.org › string-functions
String functions · JSONata
If separator is not specified, then it is assumed to be the empty string, i.e. no separator between the component strings. It is an error if separator is not a string. ... $split("too much, punctuation. hard; to read", /[ ,.;]+/, 3) ~> $join(', ') => "too, much, punctuation"
🌐
AskPython
askpython.com › home › what is json and how to merge two json strings?
What Is JSON and How To Merge Two Json Strings? - AskPython
March 16, 2023 - Taking the same strings, we have tried to merge them into a dictionary by parsing them as dictionaries first using the jsonloads() and then merging them using the **. After converting the strings into a dictionary, we merged them into a data frame.
🌐
Tabnine
tabnine.com › home page › code › java › org.json.jsonarray
org.json.JSONArray.join java code examples | Tabnine
public String join(String separator) throws JSONException { return jsonArray.join(separator);
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › org.json.jsonarray.join
JSONArray.Join(String) Method (Org.Json) | Microsoft Learn
Returns a new string by alternating this array's values with separator. [Android.Runtime.Register("join", "(Ljava/lang/String;)Ljava/lang/String;", "GetJoin_Ljava_lang_String_Handler")] public virtual string? Join(string?
Find elsewhere
🌐
KNIME Community
forum.knime.com › knime analytics platform
How to concatenate json or string outputs from two nodes - KNIME Analytics Platform - KNIME Community Forum
December 24, 2019 - Hi, I want to produce a single JSON file with two key-value pairs. I have two database views which I have used in ‘DB Query Reader’ nodes and then I am converting two outputs to two different Json using ‘Table to Json’…
🌐
Medium
medium.com › @osamakhann118 › string-concatenation-from-json-array-how-to-concatenate-string-from-json-array-b2074ae34927
String Concatenation from JSON Array | How to concatenate string from JSON array - Osama khan - Medium
December 16, 2022 - String Concatenation from JSON Array | How to concatenate string from JSON array If you want to convert a JSON objects array to a concatenated string follow the following process lets say we have a …
🌐
techtutorialsx
techtutorialsx.wordpress.com › 2020 › 09 › 06 › javascript-merge-json-objects
JavaScript merge JSON objects – techtutorialsx
January 25, 2025 - Both JSON objects will be very simple, representing possible information about a person. One of them contains two properties: name and age. The other also contains two properties: an array of languages the person speaks and a Boolean indicating if the person is married or not. const string1 = `{ "name": "Todd", "age": 20 }`; const string2 = `{ "languages": ["Spanish", "Portuguese"], "married": true }`;
🌐
Stack Overflow
stackoverflow.com › questions › 69761133 › join-all-json-object-string-values
mysql - Join all JSON object string values - Stack Overflow
select group_concat(json_unquote(json_extract(t.data, concat('$.', j.`key`))) separator '') as joined_string from mytable cross join json_table(json_keys(mytable.data), '$[*]' columns (`key` varchar(20) path '$')) j join mytable t on json_type(json_extract(t.data, concat('$.', j.`key`)))='STRING';
Top answer
1 of 3
1

It sounds like your @RemoteAction should return multiple addresses where each address looks like "city, postcode, citycode". For that to work I would expect that the JSON returned would be an array of the objects you post in the question not a single object.

The easiest way to parse such a structure is to submit an example of it to JSON2Apex and use the code that is generated.

The return type of your @RemoteAction method remains List<String> but each item in the list is:

calOut.add(p.city + ', ' + p.postcode + ', ' + p.citycode);

assuming p is a reference to the properties field of one of the returned and parsed objects.

PS

The names here depend on what the JSON fields are called but the code would look something like this:

List<String> calOut = new List<String>();
JSON2Apex parsed = JSON2Apex.parse(res.getBody());
for (JSON2Apex.Feature f : parsed.feature) {
    JSON2Apex.Properties p = f.properties;
    calOut.add(p.city + ', ' + p.postcode + ', ' + p.citycode);
}
return calOut;
2 of 3
0

Change the static method return type to string from the List<String> and

return the calOut list variable as

  @RemoteAction
  global static List<String> restapi(string accName)
  {

        string jsonStr;  
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('http://api-adresse.data.gouv.fr/search/?q=' + accName+ '');
        req.setHeader('Accept','application/JSON');
        req.setMethod('GET');
        HttpResponse res = h.send(req);
        system.debug('res.getBody()===>'+res.getBody().replace('\n', ''));
        List<String> calOut = new List<String>();

        List<String> finalcalOut = new List<String>();

        jsonStr= res.getBody();

        JSONParser parser = JSON.createParser(jsonStr);

        while (parser.nextToken() != null) 
        { 
            if (parser.getCurrentToken() == JSONToken.FIELD_NAME) 
            {

               String fieldName = parser.getText();

               if(fieldName == 'label')
               {
                  parser.nextToken();
                  calOut.add(parser.getText());               
               }        

               if(fieldName == 'context')
               {
                    parser.nextToken();
                    calOut.add(parser.getText());               
               }
               if(fieldName == 'city')
               {
                  system.debug('city  ---->'+parser.getText());  
                  parser.nextToken();
                  calOut.add(parser.getText());               
               }    
             }
             finalcalOut.add( String.join(calOut,', '); );
         }   
         return finalcalOut;
      }
    }

You would be getting something like

51, Marren, Champagne-Ardenne, Sezanne, 51120

🌐
Newtonsoft
newtonsoft.com › json › help › html › MergeJson.htm
Merging JSON
JObject o1 = JObject.Parse(@"{ ... 'Roles': [ 'User', 'Admin' ] }"); o1.Merge(o2, new JsonMergeSettings { // union array values together to avoid duplicates MergeArrayHandling = MergeArrayHandling.Union }); string json = o1.ToString(); // { // "FirstName": "John", // ...
🌐
Jon Does Flow
jondoesflow.com › post › retrieve-values-as-a-concatenated-string-from-json-object
Retrieve values as a concatenated string from JSON object
April 30, 2023 - In the screenshot below, I am selecting the Ouputs from the dynamic content from the compose step and then mapping the column "Value" to the value item from the JSON object. You'll need to write an expression for this to get this, but it will change and resolve to Value as shown in the screenshot below. That expression is item()?['Value'] After this, we need to set the StringValue variable to join each of the values from the Select statement into one string, this is done by using the following expression: join(body('Select'),',')
🌐
UiPath Community
forum.uipath.com › help › studio
Concatenate values into a string extracted from a json array via a for loop - Studio - UiPath Community Forum
April 17, 2024 - Hey, new UiPath learner here. I am trying to save some values into a string that I extracted from a complex json object and paired using a for loop. No matter what I try, how many variable scopes I change, the output ou…