-2

I am currently trying to Automate a API using HTTP client jars. I have stored the response of API which is in JSON format into a Java String object. As next step, I would like to convert the response into a JSON Object, which would help me to easily traverse the object. Can you please let me know which API jars or additional libraries I can use to convert the String object into JSON Object.

apiOutput contains the response which is in the below format.

String apiOutput= {
    "title": "foo",
    "body": "bar",
    "userId": 1,
    "id": 101
}

I would like to convert this response into a JSON object to traverse easily.

1
  • 2
    If you mean literally like in your example, that's not valid java. Commented Nov 26, 2018 at 16:02

1 Answer 1

1

Simply like this :

import org.json;

JSONObject obj = new JSONObject(jsonString);
Sign up to request clarification or add additional context in comments.

4 Comments

Which is what is written in one of the linked duplicates.
While this is correct, this question has been asked countless times on stackoverflow. Answering duplicate questions is not a good idea.
f1sh all right, I will care in the future
@TheWildHealer Thank you. Can I use Jackson or gson for this? if yes, how can I do it with them? I could not find a way as simple as org.json to do with Jackson or GSON.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.