If you are struggling to arrange the "'s the correct syntax would be

String jsonRequestString = "{\"access_code\" : \""+code+"\" , ";

Instead of formatting Json string manually, which takes alot of effort, consider using a library or util.

For ex (going to use Jackson library) :

Request re = new Request();
re.setCode(code);
...
ObjectMapper mapper = new ObjectMapper();
String jsonStr = mapper.writeValueAsString(re);
Answer from Suresh Atta on Stack Overflow
🌐
Team Treehouse
teamtreehouse.com › community › how-to-create-variables-based-on-a-json-file
How to create variables based on a json file ? (Example) | Treehouse Community
May 28, 2016 - JSONObject forecast = JSONObject(jsonData); String name = forecast.getString("Treehouse Book Series"); String publisher = forecast.getString("Wiley"); String language = forecast.getString("English"); ... { "name":"Treehouse Book Series", ...
Discussions

Convert JSON object to simple variables in Java - Stack Overflow
As a String or a text file. ... If you don't want to directly convert your input to the expected Object you could create a JSONObject from your input like ... Sign up to request clarification or add additional context in comments. ... Thank you for the answer! And what is the syntax for getting a sub-field, for example date.value? 2015-04-02T09:36:30.927Z+00:00 ... Therefore you have to navigate into the deeper JSONObject... More on stackoverflow.com
🌐 stackoverflow.com
April 1, 2015
java - Put in variables from JSON Object - Stack Overflow
Hi I'm linking a test android app to a MySQL database from an echo of JSON from a .php file. I was able to populate an ArrayList with the whole data, but now i'd like to separate the data into var... More on stackoverflow.com
🌐 stackoverflow.com
July 18, 2017
Get JSON values and convert them into Java variables - Stack Overflow
Did you already search for existing ... data in Java...? Or did you try anything else so far? ... I have been searching for a while now without finding any solution that I could implement. I have also tried out several solutions that I have found on the internet, but non of them helped me a lot. ... I suggest to use one of many JSON processing libraries available. Examples are Gson and Jackson. Both of them allow to convert: json string <--> object... More on stackoverflow.com
🌐 stackoverflow.com
How to put java variable into JSON string? - Stack Overflow
I have some variables, the value is dynamic but in this example, I'll give the fixed value of each variable. How can I put the variable in JSON string and post it to the web service? String date =... More on stackoverflow.com
🌐 stackoverflow.com
May 18, 2020
🌐
Stack Overflow
stackoverflow.com › questions › 51003739 › how-to-assign-json-to-a-variable-in-java
How to assign JSON to a variable in Java - Stack Overflow
June 24, 2018 - One can not assign valid JSON to a Java variable or object type. But how do we import valid JSON into our classes if we really want to? To do this, JSON must be converted to a JSON String. There are many tools online which do this for us.
🌐
ServiceNow Community
servicenow.com › community › developer-forum › pass-variable-value-to-json-object › m-p › 1608224
Solved: Pass variable value to json object - ServiceNow Community
July 27, 2022 - Or at least when assigning it to your literal object, assign as a string. ... var json = { "opened_by":"62826bf03710200044e0bfc8bcbe5df1", "requested_for": newReferent.toString(), "department":"221f3db5c6112284009f4becd3039cc9" }; Depending upon how and where you are assigning newReferent the ...
Top answer
1 of 1
1

First, create a pojo class with different getter/setter for your required fields.

  public class MyResponse(){

    private List<String> idList;
    private List<String> nombreList;
    private List<String> descList;
    private List<String> califList;

    public void setIdList(List<String> list){
    this.idList = list;
    }

    public void getIdList(){
    return idList;
    }

    public void setNombreList(List<String> list){
    this.nombreList = list;
    }

    public void getNombreList(){
    return nombreList;
    }

    public void setDescList(List<String> list){
    this.descList = list;
    }

    public void getDescList(){
    return descList;
    }

    public void setCalifList(List<String> list){
    this.califList = list;
    }

    public void getCalifList(){
    return califList;
    }

}

Now parse each response and add in the list of MyResponse type

         public MyResponse getDataJSON(String response)
                    {
                        MyResponse myResponse = new MyResponse();
                        ArrayList<String> idList = new ArrayList<String>();
                        ArrayList<String> nombreList = new ArrayList<String>();
                        ArrayList<String> descList = new ArrayList<String>();
                        ArrayList<String> califList = new ArrayList<String>();

                        try
                        {
                            JSONArray jsonArray = new JSONArray(response);

                            for(int i=0; i<jsonArray.length(); i++)
                            {
                              idList.add(jsonArray.getJSONObject(i).getString("id"));

   nombreList.add(jsonArray.getJSONObject(i).getString("nombre"));
                              descList.add(jsonArray.getJSONObject(i).getString("descripcion"));
                              califList.add(jsonArray.getJSONObject(i).getString("calificacion"));
                            }

                            myResponse.setIdList(idList);
                            myResponse.setNombreList(nombreList);
                            myResponse.setDescList(descList);
                            myResponse.setCalifList(califList);

                            return myResponse;
                        }

                        catch (Exception e)
                        {
                            e.printStackTrace();
                        }

                        return list;
                    }

To retrieve back the data from getDataJSON()

     MyResponse myResponse = getDataJSON(new String(responseBody)));
     ArrayList<String> idList = myResponse.getIdList();
     ArrayList<String> nombreList = myResponse.getNombreList();
     ArrayList<String> descList = myResponse.getDescList();
     ArrayList<String> califList = myResponse.getCalifList();
🌐
Stack Overflow
stackoverflow.com › questions › 61861194 › how-to-put-java-variable-into-json-string
How to put java variable into JSON string? - Stack Overflow
May 18, 2020 - import java.io.IOException; import ... = Files.readAllBytes(Paths.get("./src/main/java/gson/data.json")); String json = new String(jsonBytes); Map<String,Object> result = gson.fromJson(json, new TypeToken<Map<String, ...
Find elsewhere
🌐
Java67
java67.com › 2016 › 10 › 3-ways-to-convert-string-to-json-object-in-java.html
3 ways to convert String to JSON object in Java? Examples | Java67
Jackson is a very popular and efficient Java library to map Java objects to JSON and vice-versa. If you want to learn the basics of the Jackson library and how to use them, I suggest you take a look at the Jackson documentation. That's all about how to convert String to JSON objects in Java.
🌐
Camunda
forum.camunda.io › camunda 7 topics › discussion & questions
ExternalTaskService.complete() - how to set a variable of type JSON - Discussion & Questions - Camunda Forum
May 21, 2019 - result is a variable of type String String jsonString = “{…}” HashMap map = new HashMap result is of type Object ...
🌐
freeCodeCamp
freecodecamp.org › news › jsonobject-tostring-how-to-convert-json-to-a-string-in-java
JSONObject.toString() – How to Convert JSON to a String in Java
April 14, 2023 - In Java, the JSONObject class provided by the org.json package is commonly used to create and manipulate JSON objects. The JSONObject.toString() method is a useful method provided by this class that converts a JSON object to a string representation.
🌐
Stack Overflow
stackoverflow.com › questions › 43485994 › json-assign-java-string
JSON assign Java String - Stack Overflow
I want to get the RESULT Json to Java string or Object property. ... The default mapping for a JSON object is a LinkedHashMap<String, Object>. The simple solution would be to change the type of responseJson to that.
🌐
Stack Overflow
stackoverflow.com › questions › 14790733 › java-how-to-assign-json-formated-string-to-java-string
Java : How to assign Json formated String to Java String? - Stack Overflow
You don't need to use an Object Mapper in order to load the json from a file into a string. ... On the client-side, do a search and regex "replace all" of double-quotes into single quotes on the desired form field before actually sending the request. ... Sign up to request clarification or add additional context in comments. ... Actually, Java doesn't have verbatim string literals.
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java | Baeldung
June 20, 2025 - JSONObject – similar to Java’s native Map-like object, which stores unordered key-value pairs · JSONArray – an ordered sequence of values similar to Java’s native Vector implementation · JSONTokener – a tool that breaks a piece of text into a series of tokens that can be used by JSONObject or JSONArray to parse JSON strings
🌐
javaspring
javaspring.net › blog › how-to-assign-json-string-to-javascript-variable
How to Assign a JSON String to a JavaScript Variable: Fix EOF Errors from Improper Quoting — javaspring.net
Even with the right method, missing an escaped quote (e.g., \") or using single quotes in JSON will break things. Fix: Validate JSON with JSONLint before assigning it to a variable. ... Fix: Ensure the JavaScript string uses the same delimiter (e.g., all ", all ', or all `).