Member-only story

Creating Json Object From string in Java (Rest-assured):

https://mvnrepository.co m/artifact/org.json/json/2 0210307

get org.json from maven

add below dependency to your maven:

<!--
https://mvnrepository.com/artifact/org.json/js
on -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>

Now import these:

//import these 
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;

Now you can convert a json string to json object just like that:

//now you can convert string to array andobject without having complicated mapsand objectstry {JSONArray jsonArray = newJSONArray("[1,2,3,4,5]");//you can give entire jsonObject hereJSONObject jsonObject = newJSONObject("{\"name\": [\"praveen\"]}");System.out.println("outputarray: " +

--

--

Praveen David Mathew
Praveen David Mathew

Written by Praveen David Mathew

An open source advocator/WebdriverIO Projectcommiter/Postman Supernova/Postman-html-extra contributor/Stack overflow sqa moderator/Speaker

No responses yet