🌐
Experts Exchange
experts-exchange.com › questions › 28652216 › How-to-get-convert-json-array-to-comma-separated-values.html
Solved: How to get convert json array to comma separated values | Experts Exchange
April 8, 2015 - I would like to convert the following json array to comma separated values i/p: [{"filter":"ID","filterVal ... "050882"; I tried the below code , but I am getting exception while getting filter values. Any help would be appreciated. String input ='[{"filter":"ID","filterValues":["050886","050885","050884","050883","050882"]}]'; JSONArray jsonarray = (JSONArray) new JSONTokener(input ).nextValue(); for (int i = 0; i < jsonarray.length(); i++) { JSONObject jsonobject = jsonarray.getJSONObject(i); String field= jsonobject.getString("filter"); String values= jsonobject.getString("filterValues"); }
🌐
Blogger
self-learning-java-tutorial.blogspot.com › 2019 › 03 › convert-jsonarray-to-comma-separated.html
Programming for beginners: Convert JSONArray to comma separated string
March 16, 2019 - JavaScript · Julia · Kotlin · Nexus · Node.js · Prolog Tutorial · Python · R Tutorial for beginners · Spring Framework · XML · YAML · CDL.rowToString(jsonArray) method returns a comma separated string from JSONArray. JSONArray jsonArray = new JSONArray(); jsonArray.put("Chess"); ...
🌐
Kodejava
kodejava.org › how-do-i-convert-csv-into-json-string-using-json-java
How do I convert CSV into JSON string using JSON-Java? - Learn Java by Examples
July 13, 2023 - package org.kodejava.json; import org.json.CDL; import org.json.JSONArray; public class CsvToJson { public static void main(String[] args) { // Comma delimited text created using text blocks String countries = """ ISO, CODE, NAME\s CZE, CZ, CZECH REPUBLIC\s DNK, DK, DENMARK\s DJI, DJ, DJIBOUTI\s DMA, DM, DOMINICA\s ECU, EC, ECUADOR """; // Convert comma delimited text into JSONArray object. JSONArray jsonCountries = CDL.toJSONArray(countries); System.out.println(jsonCountries.toString(2)); // Using a separate header and values to create JSONArray // from a comma delimited text JSONArray header
🌐
Blogger
javarevisited.blogspot.com › 2016 › 03 › how-to-convert-array-to-comma-separated-string-in-java.html
How to Convert an Array to Comma Separated String in Java - Example Tutorial
June 22, 2025 - The simplest way to convert an array to comma separated String is to create a StringBuilder, iterate through the array, and add each element of the array into StringBuilder after appending the comma.
🌐
PCSalt
java.pcsalt.com › home › convert json values into comma separated values - java
Convert JSON values into comma separated values - Java | PCSalt
November 4, 2020 - And this JSON needs to be converted into comma separated values like · app=(versionCode=15,versionName=1.4.6,name=latitude),os=(name=android,version=11) This JAVA method getCommaSeparated() accepts JSONObject and return string in the comma separated format.
🌐
ServiceNow Community
servicenow.com › community › developer-forum › convert-array-string-to-comma-separated-string › m-p › 2606171
Convert Array String to Comma Separated String - ServiceNow Community
July 6, 2023 - Hi, I suspect your issue is that your array is an array of objects, and so may need to iterate through the sorted array stringifying each element\object and concatenating these individually to your output string. ... var tempString = ''; for(key in sortedArray) { tempString = tempString + JSON.stringify(sortedArray[key]); }
🌐
Blogger
javarevisited.blogspot.com › 2016 › 03 › how-to-convert-array-to-comma-separated-string-in-java.html
Javarevisited: How to Convert an Array to Comma Separated String in Java - Example Tutorial
Learn Java, Programming, Spring, ... comma separated String is to create a StringBuilder, iterate through the array, and add each element of the array into StringBuilder after appending the comma....
🌐
JBoss.org
developer.jboss.org › thread › 262563
convert a comma separated string to json array| JBoss.org Content Archive (Read Only)
The return type for JSONARRAY is clob. > If i convert the datatype the datatype of the column to clob, my odata url gives the below error · Do you have a primary key on column_string or are using it in another transformation where you expect it be comparable/sortable? By default clobs are not comparable. Generally what you would do is convert from clob to string (assuming that your json values are under 4000 characters) - cast(JSONARRAY(...) as string)
Find elsewhere
🌐
n8n
community.n8n.io › questions
Json to array comma - Questions - n8n Community
May 16, 2022 - Hello everyone. I trying to convert a json data to a string comma separated. Json is like this one: [ { "id": "625d757724acbe52634e6172", "idBoard": "625850ac4247c214ff3dc167", "name": "ANGELIS", "color": "yellow" }, { "id": "625d57da6bfa728b6684ed43", "idBoard": "625850ac4247c214ff3dc167", ...
Top answer
1 of 3
4

For such a trivial example, it's pretty easy to produce a poorly-formed JSON String of your content and let JSONObject patch it up.

In a single expression:

new JSONObject(String.format("{%s}", str.replaceAll("([^,]+),([^,]+)(,|$)", "$1:$2,")))
// {"art":0,"comedy":0,"action":0,"crime":0,"animals":0}

If you really want to keep the 0.0 as Strings:

new JSONObject(String.format("{%s}", str.replaceAll("([^,]+),([^,]+)(,|$)", "$1:\"$2\",")))
// {"art":"0.0","comedy":"0.0","action":"0.0","crime":"0.0","animals":"0.0"}

If you want to account for possible extraneous whitespaces:

new JSONObject(String.format("{%s}", str.replaceAll("([^,]+)\\s*?,\\s*?([^,]+)(,|$)", "$1:$2,")))

.. will work with inputs like "art, 0.0, comedy, 0.0, action, 0.0, crime, 0.0, animals, 0.0" and other cases.


Disclaimer: it's not crazy-sexy code but drop in a one-line comment and it could be reasonable so long as the data structure stays simplistic.

2 of 3
2

You should use Map instead of Array (List of key/value pair is Map, not Array).

1 way: Using JsonObject

String [] arrayStr=strVal.split(",");
JsonObjectBuilder builder = Json.createObjectBuilder()

String key = null;
for (String s: arrayStr){
    if(key == null) {
       key = s;
    } else {
       builder.add(key, s);
       key = null;
    }
}
JsonObject value = builder.build();

2 way: Using Map

String [] arrayStr=strVal.split(",");
Map<String,String> map = new HashMap<>();

String key = null;
for (String s: arrayStr){
    if(key == null) {
       key = s;
    } else {
       map.put(key, s);
       key = null;
    }
}

// convert Map to Json using any Json lib (Gson, Jackson and so on)
🌐
Stack Overflow
stackoverflow.com › questions › 70357603 › how-to-convert-single-string-containing-a-comma-separated-json-values-into-a-sin
java - How to convert single String containing a comma separated json values into a single json object? - Stack Overflow
... Are you sure that's the actual data? Because if it is, first strip the outer double quotes and then run through your string, counting { and }, and splitting when you see a comma while at "depth" 0.
🌐
Cyber-Physical Systems
ptolemy.berkeley.edu › ptolemyII › ptII11.0 › ptII › doc › codeDoc › org › json › CDL.html
CDL
Produce a JSONObject from a row of comma delimited text, using a parallel JSONArray of strings to provides the names of the elements. ... names - A JSONArray of names. This is commonly obtained from the first row of a comma delimited text file using the rowToJSONArray method.
🌐
OneCompiler
onecompiler.com › javascript › 3xfqsme8y
convert a json array of objects to comma separated values - JavaScript - OneCompiler
Executable in both browser and server which has Javascript engines like V8(chrome), SpiderMonkey(Firefox) etc. var readline = require("readline") var rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false, }) rl.on("line", function (line) { console.log("Hello, " + line) }) ... An array is a collection of items or values.
🌐
Wappler Community
community.wappler.io › wappler general › need help
Show json array field as comma separated values - Need Help - Wappler Community
July 1, 2023 - I have a JSON field which stored days of the week. I want to show those in my list but it’s displaying them like this: ["Mon","Tue","Wed","Thu","Fri"] I’m sure it must be easy to change this but cannot find how. I wan…
🌐
Microsoft Power Platform Community
powerusers.microsoft.com › t5 › Building-Flows › JSON-received-as-a-comma-separated-string-need-help-in › td-p › 676482
https://powerusers.microsoft.com/t5/Building-Flows...
Quickly search for answers, join discussions, post questions, and work smarter in your business applications by joining the Microsoft Dynamics 365 Community.
🌐
Stack Overflow
stackoverflow.com › questions › 55480355 › comma-separated-values-in-json-array-are-treated-as-delimiters
java - Comma Separated values in json array are treated as delimiters - Stack Overflow
April 3, 2019 - ... Please provide a minimal reproducible example. ... You should create a POJO class that is equivalent to the JSon String format. Then you can use jackson to convert the JSon string to pojo objects. It will not have the mentioned issue. Reference : https://www.mkyong.com/java/how-to-conv...