How can I convert String to JSON object in Java?

+15 votes

I am working on a String. I want to convert it into JSONobject. How can I do this?

Announcement! Career Guide 2019 is out now. Explore careers to become a Big Data Developer or Architect!

Apr 27, 2018 in Java by Daisy
• 8,090 points

edited Apr 12, 2019 by Vardhan 174,846 views

21 answers to this question.

+4 votes
Best answer

Hi @Daisy

You can use Google gson 

for more details

The object in examples:

class BagOfPrimitives {
  private int value1 = 1;
  private String value2 = "abc";
  private transient int value3 = 3;
  BagOfPrimitives() {
    // no-args constructor
  }
} 

Serialization

BagOfPrimitives obj = new BagOfPrimitives();
Gson gson = new Gson();
String json = gson.toJson(obj); 
==> json is {"value1":1,"value2":"abc"} 

Note that you can not serialize objects with circular references since that will result in infinite recursion.

(Deserialization)

BagOfPrimitives obj2 = gson.fromJson(json, BagOfPrimitives.class);  
==> obj2 is just like obj

Another example of Gson:

Gson is easy to learn and implement, you need to know is the following two methods:

-> toJson() – convert java object to JSON format

-> fromJson() – convert JSON into java object

import com.google.gson.Gson;

public class TestObjectToJson {
  private int data1 = 100;
  private String data2 = "hello";

  public static void main(String[] args) {
      TestObjectToJson obj = new TestObjectToJson();
      Gson gson = new Gson();

      //convert java object to JSON format
      String json = gson.toJson(obj);

      System.out.println(json);
  }

}
Output

{"data1":100,"data2":"hello"}

Resources.

Google Gson project home

Thanks 

Sureshprabhu

answered Feb 7, 2019 by Suresh
• 720 points

selected Feb 7, 2019 by Omkar
+3 votes

If you have a String and want to convert it into JSONObject, you should use or.json library.

JSONObject jsonObj = new JSONObject("{\"firstname\":\"John\",\"lastname\":\"Lee\"}");
answered Apr 27, 2018 by Parth
• 4,630 points
+3 votes

Try GSON, GSON directly converts a string to a java object

Example:

String jsonString = {"Name": "Harry Potter"}
create a new class:
class Name {
@SerializedName("name")
private String name;
public void setname(String name) {
this.name = name;
}
public String getname(){
return name;
}
}

// in java

Gson gson = new Gson();
Name name = gson.fromJson(jsonString, Name.class);
System.out.println("Name is "+name.getname());
answered Aug 6, 2018 by Kalgi
• 51,890 points
0 votes
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(stringToParse);

You can use this code.
Hope this helps.

answered Aug 6, 2018 by Priyaj
• 57,550 points

The type JSONParser is deprecated

The type JSONObject is deprecated

What application are you running it on?

I did a little research and found that the use of JSONParser is deprecated. The documentation says:

JSONParser is deprecated. The new usage is JSONParser(JSONParser.MODE_*)

Try the new usage and see if it works.

+2 votes

Another simple approach:

Name name = new ObjectMapper().readValue(jsonString, Player.class);
answered Aug 6, 2018 by Omkar
• 69,020 points
+2 votes
import javax.json.*;

...

String TEXT;
JsonObject body = Json.createReader(new StringReader(TEXT)).readObject()
answered Nov 13, 2018 by FIroz
0 votes

You can use Gson it is an open source library to deal with JSON. You can convert JSON String to Java object in just 2 lines by using Gson as shown below :
Gson g = new Gson(); Player p = g.fromJson(jsonString, Player.class)

You can also convert a Java object to JSON by using toJson() method as shown below

String str = g.toJson(p);
answered Nov 13, 2018 by Priyaj
• 57,550 points
0 votes

You can use google-gson:

class Phone {
 public String name;
}


...
String jsonString = "{\"name\":\"WP\"}";
Gson gson = new Gson();
Phone fooFromJson = gson.fromJson(jsonString, Phone.class);
...
answered Nov 13, 2018 by Richard
–1 vote

JSON-Simple is open source library which supports JSON parsing and formatting.

JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(stringToParse);
answered Nov 13, 2018 by Jino
• 5,670 points

The type JSONParser is deprecated

The type JSONObject is deprecated

I am getting different error:

you need to add jar in build path. perhaps this is deprecated.

use the new way https://www.edureka.co/community/2351/how-can-i-convert-string-to-json-object-in-java?start=10#a_list_title.

Tried that, no luck!

–1 vote

The simplest way to achieve this 

JSONParser parser = new JSONParser(); 
JSONObject json = (JSONObject) parser.parse(stringToParse);

answered Nov 13, 2018 by Maverick
• 10,820 points

The type JSONParser is deprecated

The type JSONObject is deprecated

0 votes

object name = new ObjectMapper().readValue(jsonString, object.class);

Hope this helps

answered Nov 13, 2018 by Ali
• 10,670 points
0 votes

//package details

import org.json.simple.JsonObject;

import org.json.simple.Jsoner;

//logic

JsonObject jsonObject = (JsonObject) Jsoner.deserialize(JSON_STRING_VALUE);

answered Jan 7, 2019 by ajay
• 190 points
–3 votes
{
"method" : "conferenceCallout",
"conferenceCallout" :
{
"cli" : "amanda",
"destination" : { "type" : "number", "endpoint" : "+919986351005" },
"domain" : "pstn",
"custom" : "customData",
"locale" : "en-US",
"greeting" : "Welcome to my conference",
"conferenceId" : "myConference",
"enableAce": false,
"enableDice" : false
}
}
answered Jan 28, 2019 by anonymous
0 votes
Gson g = new Gson();
Player p = g.fromJson(jsonString, Player.class)



example of json are

jsonString = {
  "name" : "rajesh",
  "sport" : "cricket",
  "age" : 25,
  "id" : 121,
  "lastScores" : [ 20, 10, 3o, 5, 10, 0, 11, 100 ]
}

 

answered Feb 4, 2019 by rajesh
• 1,230 points
–1 vote
public class HelloWord{

    public static void main(String []args){

       String s = "{\"swagger\\\":\\\"2.0\\\",\\\"paths\\\":{\\\"/upi/ReqPay\\\":{\\\"post\\\":{\\\"parameters\\\":[{\\\"name\\\":\\\"Payload\\\",\\\"description\\\":\\\"Request Body\\\",\\\"required\\\":false,\\\"in\\\":\\\"body\\\",\\\"schema\\\":{\\\"type\\\":\\\"object\\\",\\\"properties\\\":{\\\"payload\\\":{\\\"type\\\":\\\"string\\\"}}}}],\\\"responses\\\":{\\\"200\\\":{\\\"description\\\":\\\"\\\"}},\\\"produces\\\":[\\\"application/xml\\\"],\\\"consumes\\\":[\\\"application/xml\\\"],\\\"x-auth-type\\\":\\\"Application & Application User\\\",\\\"x-throttling-tier\\\":\\\"Unlimited\\\"}}},\\\"info\\\":{\\\"title\\\":\\\"RequestPay\\\",\\\"version\\\":\\\"1.0.0\\\",\\\"description\\\":\\\"API is used for both Direct Pay and Collect Pay transaction\\\\ninitiation by the PSPs and processing the transaction through\\\\none of the following channels IMPS,AEPS etc. \\\"}}\"";

       System.out.println(s.replace("\\"," "));

    }

}
answered Mar 26, 2019 by anonymous
0 votes

example of convert String to JSON object in Java?

jsonstring

jsonString = {
  "name" : "Ronaldo",
  "sport" : "soccer",
  "age" : 25,
  "id" : 121,
  "lastScores" : [ 2, 1, 3, 5, 0, 0, 1, 1 ] 

}

string to json object with using gson

The Gson is an open source library to deal with JSON in Java programs.You can convert JSON String to Java object in just 2 lines by using Gson as shown below

Gson g = new Gson(); 

Player p =g.fromJson(jsonString, Player.class)

You can also convert a Java object to JSON by using to Json() method as shown below

String str = g.toJson(p);

answered Apr 3, 2019 by navdeep
• 330 points
I as well as my pals ended up viewing the good thoughts from your site then quickly got an awful feeling I never expressed respect to the web blog owner for those tips. All of the young men appeared to be for that reason excited to study all of them and have honestly been loving these things. Thank you for indeed being well accommodating and for pick out such incredible things millions of individuals are really wanting to learn about. Our honest regret for not expressing appreciation to  earlier.
hermes birkin http://www.hermesbirkinbags.us.com
0 votes
{
  "total_count": 513,
  "incomplete_results": false,
  "items": [
    {
      "login": "moyheen",
      "id": 8110201,
      "node_id": "MDQ6VXNlcjgxMTAyMDE=",
      "avatar_url": "https://avatars2.githubusercontent.com/u/8110201?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/moyheen",
      "html_url": "https://github.com/moyheen",
      "followers_url": "https://api.github.com/users/moyheen/followers",
      "following_url": "https://api.github.com/users/moyheen/following{/other_user}",
      "gists_url": "https://api.github.com/users/moyheen/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/moyheen/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/moyheen/subscriptions",
      "organizations_url": "https://api.github.com/users/moyheen/orgs",
      "repos_url": "https://api.github.com/users/moyheen/repos",
      "events_url": "https://api.github.com/users/moyheen/events{/privacy}",
      "received_events_url": "https://api.github.com/users/moyheen/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "o-kamiye",
      "id": 4929406,
      "node_id": "MDQ6VXNlcjQ5Mjk0MDY=",
      "avatar_url": "https://avatars1.githubusercontent.com/u/4929406?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/o-kamiye",
      "html_url": "https://github.com/o-kamiye",
      "followers_url": "https://api.github.com/users/o-kamiye/followers",
      "following_url": "https://api.github.com/users/o-kamiye/following{/other_user}",
      "gists_url": "https://api.github.com/users/o-kamiye/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/o-kamiye/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/o-kamiye/subscriptions",
      "organizations_url": "https://api.github.com/users/o-kamiye/orgs",
      "repos_url": "https://api.github.com/users/o-kamiye/repos",
      "events_url": "https://api.github.com/users/o-kamiye/events{/privacy}",
      "received_events_url": "https://api.github.com/users/o-kamiye/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "aliumujib",
      "id": 13552664,
      "node_id": "MDQ6VXNlcjEzNTUyNjY0",
      "avatar_url": "https://avatars3.githubusercontent.com/u/13552664?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/aliumujib",
      "html_url": "https://github.com/aliumujib",
      "followers_url": "https://api.github.com/users/aliumujib/followers",
      "following_url": "https://api.github.com/users/aliumujib/following{/other_user}",
      "gists_url": "https://api.github.com/users/aliumujib/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/aliumujib/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/aliumujib/subscriptions",
      "organizations_url": "https://api.github.com/users/aliumujib/orgs",
      "repos_url": "https://api.github.com/users/aliumujib/repos",
      "events_url": "https://api.github.com/users/aliumujib/events{/privacy}",
      "received_events_url": "https://api.github.com/users/aliumujib/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "biodunalfet",
      "id": 6963510,
      "node_id": "MDQ6VXNlcjY5NjM1MTA=",
      "avatar_url": "https://avatars1.githubusercontent.com/u/6963510?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/biodunalfet",
      "html_url": "https://github.com/biodunalfet",
      "followers_url": "https://api.github.com/users/biodunalfet/followers",
      "following_url": "https://api.github.com/users/biodunalfet/following{/other_user}",
      "gists_url": "https://api.github.com/users/biodunalfet/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/biodunalfet/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/biodunalfet/subscriptions",
      "organizations_url": "https://api.github.com/users/biodunalfet/orgs",
      "repos_url": "https://api.github.com/users/biodunalfet/repos",
      "events_url": "https://api.github.com/users/biodunalfet/events{/privacy}",
      "received_events_url": "https://api.github.com/users/biodunalfet/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "helios66",
      "id": 678974,
      "node_id": "MDQ6VXNlcjY3ODk3NA==",
      "avatar_url": "https://avatars3.githubusercontent.com/u/678974?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/helios66",
      "html_url": "https://github.com/helios66",
      "followers_url": "https://api.github.com/users/helios66/followers",
      "following_url": "https://api.github.com/users/helios66/following{/other_user}",
      "gists_url": "https://api.github.com/users/helios66/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/helios66/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/helios66/subscriptions",
      "organizations_url": "https://api.github.com/users/helios66/orgs",
      "repos_url": "https://api.github.com/users/helios66/repos",
      "events_url": "https://api.github.com/users/helios66/events{/privacy}",
      "received_events_url": "https://api.github.com/users/helios66/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "tundeojediran",
      "id": 6113672,
      "node_id": "MDQ6VXNlcjYxMTM2NzI=",
      "avatar_url": "https://avatars0.githubusercontent.com/u/6113672?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/tundeojediran",
      "html_url": "https://github.com/tundeojediran",
      "followers_url": "https://api.github.com/users/tundeojediran/followers",
      "following_url": "https://api.github.com/users/tundeojediran/following{/other_user}",
      "gists_url": "https://api.github.com/users/tundeojediran/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/tundeojediran/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/tundeojediran/subscriptions",
      "organizations_url": "https://api.github.com/users/tundeojediran/orgs",
      "repos_url": "https://api.github.com/users/tundeojediran/repos",
      "events_url": "https://api.github.com/users/tundeojediran/events{/privacy}",
      "received_events_url": "https://api.github.com/users/tundeojediran/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "KingsMentor",
      "id": 5605785,
      "node_id": "MDQ6VXNlcjU2MDU3ODU=",
      "avatar_url": "https://avatars1.githubusercontent.com/u/5605785?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/KingsMentor",
      "html_url": "https://github.com/KingsMentor",
      "followers_url": "https://api.github.com/users/KingsMentor/followers",
      "following_url": "https://api.github.com/users/KingsMentor/following{/other_user}",
      "gists_url": "https://api.github.com/users/KingsMentor/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/KingsMentor/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/KingsMentor/subscriptions",
      "organizations_url": "https://api.github.com/users/KingsMentor/orgs",
      "repos_url": "https://api.github.com/users/KingsMentor/repos",
      "events_url": "https://api.github.com/users/KingsMentor/events{/privacy}",
      "received_events_url": "https://api.github.com/users/KingsMentor/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "adetuyiTolu",
      "id": 19608533,
      "node_id": "MDQ6VXNlcjE5NjA4NTMz",
      "avatar_url": "https://avatars1.githubusercontent.com/u/19608533?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/adetuyiTolu",
      "html_url": "https://github.com/adetuyiTolu",
      "followers_url": "https://api.github.com/users/adetuyiTolu/followers",
      "following_url": "https://api.github.com/users/adetuyiTolu/following{/other_user}",
      "gists_url": "https://api.github.com/users/adetuyiTolu/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/adetuyiTolu/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/adetuyiTolu/subscriptions",
      "organizations_url": "https://api.github.com/users/adetuyiTolu/orgs",
      "repos_url": "https://api.github.com/users/adetuyiTolu/repos",
      "events_url": "https://api.github.com/users/adetuyiTolu/events{/privacy}",
      "received_events_url": "https://api.github.com/users/adetuyiTolu/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "kizitonwose",
      "id": 15170090,
      "node_id": "MDQ6VXNlcjE1MTcwMDkw",
      "avatar_url": "https://avatars2.githubusercontent.com/u/15170090?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/kizitonwose",
      "html_url": "https://github.com/kizitonwose",
      "followers_url": "https://api.github.com/users/kizitonwose/followers",
      "following_url": "https://api.github.com/users/kizitonwose/following{/other_user}",
      "gists_url": "https://api.github.com/users/kizitonwose/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/kizitonwose/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/kizitonwose/subscriptions",
      "organizations_url": "https://api.github.com/users/kizitonwose/orgs",
      "repos_url": "https://api.github.com/users/kizitonwose/repos",
      "events_url": "https://api.github.com/users/kizitonwose/events{/privacy}",
      "received_events_url": "https://api.github.com/users/kizitonwose/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "emmanuelkehinde",
      "id": 16584163,
      "node_id": "MDQ6VXNlcjE2NTg0MTYz",
      "avatar_url": "https://avatars3.githubusercontent.com/u/16584163?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/emmanuelkehinde",
      "html_url": "https://github.com/emmanuelkehinde",
      "followers_url": "https://api.github.com/users/emmanuelkehinde/followers",
      "following_url": "https://api.github.com/users/emmanuelkehinde/following{/other_user}",
      "gists_url": "https://api.github.com/users/emmanuelkehinde/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/emmanuelkehinde/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/emmanuelkehinde/subscriptions",
      "organizations_url": "https://api.github.com/users/emmanuelkehinde/orgs",
      "repos_url": "https://api.github.com/users/emmanuelkehinde/repos",
      "events_url": "https://api.github.com/users/emmanuelkehinde/events{/privacy}",
      "received_events_url": "https://api.github.com/users/emmanuelkehinde/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "SeunAdelekan",
      "id": 16557263,
      "node_id": "MDQ6VXNlcjE2NTU3MjYz",
      "avatar_url": "https://avatars2.githubusercontent.com/u/16557263?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/SeunAdelekan",
      "html_url": "https://github.com/SeunAdelekan",
      "followers_url": "https://api.github.com/users/SeunAdelekan/followers",
      "following_url": "https://api.github.com/users/SeunAdelekan/following{/other_user}",
      "gists_url": "https://api.github.com/users/SeunAdelekan/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/SeunAdelekan/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/SeunAdelekan/subscriptions",
      "organizations_url": "https://api.github.com/users/SeunAdelekan/orgs",
      "repos_url": "https://api.github.com/users/SeunAdelekan/repos",
      "events_url": "https://api.github.com/users/SeunAdelekan/events{/privacy}",
      "received_events_url": "https://api.github.com/users/SeunAdelekan/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "cornzyblack",
      "id": 5692718,
      "node_id": "MDQ6VXNlcjU2OTI3MTg=",
      "avatar_url": "https://avatars2.githubusercontent.com/u/5692718?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/cornzyblack",
      "html_url": "https://github.com/cornzyblack",
      "followers_url": "https://api.github.com/users/cornzyblack/followers",
      "following_url": "https://api.github.com/users/cornzyblack/following{/other_user}",
      "gists_url": "https://api.github.com/users/cornzyblack/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/cornzyblack/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/cornzyblack/subscriptions",
      "organizations_url": "https://api.github.com/users/cornzyblack/orgs",
      "repos_url": "https://api.github.com/users/cornzyblack/repos",
      "events_url": "https://api.github.com/users/cornzyblack/events{/privacy}",
      "received_events_url": "https://api.github.com/users/cornzyblack/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "timi-codes",
      "id": 7896429,
      "node_id": "MDQ6VXNlcjc4OTY0Mjk=",
      "avatar_url": "https://avatars1.githubusercontent.com/u/7896429?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/timi-codes",
      "html_url": "https://github.com/timi-codes",
      "followers_url": "https://api.github.com/users/timi-codes/followers",
      "following_url": "https://api.github.com/users/timi-codes/following{/other_user}",
      "gists_url": "https://api.github.com/users/timi-codes/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/timi-codes/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/timi-codes/subscriptions",
      "organizations_url": "https://api.github.com/users/timi-codes/orgs",
      "repos_url": "https://api.github.com/users/timi-codes/repos",
      "events_url": "https://api.github.com/users/timi-codes/events{/privacy}",
      "received_events_url": "https://api.github.com/users/timi-codes/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "chalu",
      "id": 276286,
      "node_id": "MDQ6VXNlcjI3NjI4Ng==",
      "avatar_url": "https://avatars0.githubusercontent.com/u/276286?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/chalu",
      "html_url": "https://github.com/chalu",
      "followers_url": "https://api.github.com/users/chalu/followers",
      "following_url": "https://api.github.com/users/chalu/following{/other_user}",
      "gists_url": "https://api.github.com/users/chalu/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/chalu/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/chalu/subscriptions",
      "organizations_url": "https://api.github.com/users/chalu/orgs",
      "repos_url": "https://api.github.com/users/chalu/repos",
      "events_url": "https://api.github.com/users/chalu/events{/privacy}",
      "received_events_url": "https://api.github.com/users/chalu/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "yomiolatunji",
      "id": 5986979,
      "node_id": "MDQ6VXNlcjU5ODY5Nzk=",
      "avatar_url": "https://avatars2.githubusercontent.com/u/5986979?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/yomiolatunji",
      "html_url": "https://github.com/yomiolatunji",
      "followers_url": "https://api.github.com/users/yomiolatunji/followers",
      "following_url": "https://api.github.com/users/yomiolatunji/following{/other_user}",
      "gists_url": "https://api.github.com/users/yomiolatunji/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/yomiolatunji/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/yomiolatunji/subscriptions",
      "organizations_url": "https://api.github.com/users/yomiolatunji/orgs",
      "repos_url": "https://api.github.com/users/yomiolatunji/repos",
      "events_url": "https://api.github.com/users/yomiolatunji/events{/privacy}",
      "received_events_url": "https://api.github.com/users/yomiolatunji/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "larikraun",
      "id": 2240178,
      "node_id": "MDQ6VXNlcjIyNDAxNzg=",
      "avatar_url": "https://avatars2.githubusercontent.com/u/2240178?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/larikraun",
      "html_url": "https://github.com/larikraun",
      "followers_url": "https://api.github.com/users/larikraun/followers",
      "following_url": "https://api.github.com/users/larikraun/following{/other_user}",
      "gists_url": "https://api.github.com/users/larikraun/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/larikraun/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/larikraun/subscriptions",
      "organizations_url": "https://api.github.com/users/larikraun/orgs",
      "repos_url": "https://api.github.com/users/larikraun/repos",
      "events_url": "https://api.github.com/users/larikraun/events{/privacy}",
      "received_events_url": "https://api.github.com/users/larikraun/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "AdoraNwodo",
      "id": 13754478,
      "node_id": "MDQ6VXNlcjEzNzU0NDc4",
      "avatar_url": "https://avatars0.githubusercontent.com/u/13754478?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/AdoraNwodo",
      "html_url": "https://github.com/AdoraNwodo",
      "followers_url": "https://api.github.com/users/AdoraNwodo/followers",
      "following_url": "https://api.github.com/users/AdoraNwodo/following{/other_user}",
      "gists_url": "https://api.github.com/users/AdoraNwodo/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/AdoraNwodo/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/AdoraNwodo/subscriptions",
      "organizations_url": "https://api.github.com/users/AdoraNwodo/orgs",
      "repos_url": "https://api.github.com/users/AdoraNwodo/repos",
      "events_url": "https://api.github.com/users/AdoraNwodo/events{/privacy}",
      "received_events_url": "https://api.github.com/users/AdoraNwodo/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "TaslimOseni",
      "id": 19727515,
      "node_id": "MDQ6VXNlcjE5NzI3NTE1",
      "avatar_url": "https://avatars2.githubusercontent.com/u/19727515?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/TaslimOseni",
      "html_url": "https://github.com/TaslimOseni",
      "followers_url": "https://api.github.com/users/TaslimOseni/followers",
      "following_url": "https://api.github.com/users/TaslimOseni/following{/other_user}",
      "gists_url": "https://api.github.com/users/TaslimOseni/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/TaslimOseni/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/TaslimOseni/subscriptions",
      "organizations_url": "https://api.github.com/users/TaslimOseni/orgs",
      "repos_url": "https://api.github.com/users/TaslimOseni/repos",
      "events_url": "https://api.github.com/users/TaslimOseni/events{/privacy}",
      "received_events_url": "https://api.github.com/users/TaslimOseni/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "chikecodes",
      "id": 9150660,
      "node_id": "MDQ6VXNlcjkxNTA2NjA=",
      "avatar_url": "https://avatars0.githubusercontent.com/u/9150660?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/chikecodes",
      "html_url": "https://github.com/chikecodes",
      "followers_url": "https://api.github.com/users/chikecodes/followers",
      "following_url": "https://api.github.com/users/chikecodes/following{/other_user}",
      "gists_url": "https://api.github.com/users/chikecodes/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/chikecodes/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/chikecodes/subscriptions",
      "organizations_url": "https://api.github.com/users/chikecodes/orgs",
      "repos_url": "https://api.github.com/users/chikecodes/repos",
      "events_url": "https://api.github.com/users/chikecodes/events{/privacy}",
      "received_events_url": "https://api.github.com/users/chikecodes/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "IEnoobong",
      "id": 7225217,
      "node_id": "MDQ6VXNlcjcyMjUyMTc=",
      "avatar_url": "https://avatars3.githubusercontent.com/u/7225217?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/IEnoobong",
      "html_url": "https://github.com/IEnoobong",
      "followers_url": "https://api.github.com/users/IEnoobong/followers",
      "following_url": "https://api.github.com/users/IEnoobong/following{/other_user}",
      "gists_url": "https://api.github.com/users/IEnoobong/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/IEnoobong/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/IEnoobong/subscriptions",
      "organizations_url": "https://api.github.com/users/IEnoobong/orgs",
      "repos_url": "https://api.github.com/users/IEnoobong/repos",
      "events_url": "https://api.github.com/users/IEnoobong/events{/privacy}",
      "received_events_url": "https://api.github.com/users/IEnoobong/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "androidmaven",
      "id": 21104847,
      "node_id": "MDQ6VXNlcjIxMTA0ODQ3",
      "avatar_url": "https://avatars2.githubusercontent.com/u/21104847?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/androidmaven",
      "html_url": "https://github.com/androidmaven",
      "followers_url": "https://api.github.com/users/androidmaven/followers",
      "following_url": "https://api.github.com/users/androidmaven/following{/other_user}",
      "gists_url": "https://api.github.com/users/androidmaven/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/androidmaven/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/androidmaven/subscriptions",
      "organizations_url": "https://api.github.com/users/androidmaven/orgs",
      "repos_url": "https://api.github.com/users/androidmaven/repos",
      "events_url": "https://api.github.com/users/androidmaven/events{/privacy}",
      "received_events_url": "https://api.github.com/users/androidmaven/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "Kennypee",
      "id": 20874031,
      "node_id": "MDQ6VXNlcjIwODc0MDMx",
      "avatar_url": "https://avatars2.githubusercontent.com/u/20874031?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/Kennypee",
      "html_url": "https://github.com/Kennypee",
      "followers_url": "https://api.github.com/users/Kennypee/followers",
      "following_url": "https://api.github.com/users/Kennypee/following{/other_user}",
      "gists_url": "https://api.github.com/users/Kennypee/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/Kennypee/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/Kennypee/subscriptions",
      "organizations_url": "https://api.github.com/users/Kennypee/orgs",
      "repos_url": "https://api.github.com/users/Kennypee/repos",
      "events_url": "https://api.github.com/users/Kennypee/events{/privacy}",
      "received_events_url": "https://api.github.com/users/Kennypee/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "ajibigad",
      "id": 4974988,
      "node_id": "MDQ6VXNlcjQ5NzQ5ODg=",
      "avatar_url": "https://avatars3.githubusercontent.com/u/4974988?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/ajibigad",
      "html_url": "https://github.com/ajibigad",
      "followers_url": "https://api.github.com/users/ajibigad/followers",
      "following_url": "https://api.github.com/users/ajibigad/following{/other_user}",
      "gists_url": "https://api.github.com/users/ajibigad/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/ajibigad/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/ajibigad/subscriptions",
      "organizations_url": "https://api.github.com/users/ajibigad/orgs",
      "repos_url": "https://api.github.com/users/ajibigad/repos",
      "events_url": "https://api.github.com/users/ajibigad/events{/privacy}",
      "received_events_url": "https://api.github.com/users/ajibigad/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "Elvis10ten",
      "id": 4107815,
      "node_id": "MDQ6VXNlcjQxMDc4MTU=",
      "avatar_url": "https://avatars0.githubusercontent.com/u/4107815?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/Elvis10ten",
      "html_url": "https://github.com/Elvis10ten",
      "followers_url": "https://api.github.com/users/Elvis10ten/followers",
      "following_url": "https://api.github.com/users/Elvis10ten/following{/other_user}",
      "gists_url": "https://api.github.com/users/Elvis10ten/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/Elvis10ten/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/Elvis10ten/subscriptions",
      "organizations_url": "https://api.github.com/users/Elvis10ten/orgs",
      "repos_url": "https://api.github.com/users/Elvis10ten/repos",
      "events_url": "https://api.github.com/users/Elvis10ten/events{/privacy}",
      "received_events_url": "https://api.github.com/users/Elvis10ten/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "Ezike",
      "id": 17779130,
      "node_id": "MDQ6VXNlcjE3Nzc5MTMw",
      "avatar_url": "https://avatars1.githubusercontent.com/u/17779130?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/Ezike",
      "html_url": "https://github.com/Ezike",
      "followers_url": "https://api.github.com/users/Ezike/followers",
      "following_url": "https://api.github.com/users/Ezike/following{/other_user}",
      "gists_url": "https://api.github.com/users/Ezike/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/Ezike/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/Ezike/subscriptions",
      "organizations_url": "https://api.github.com/users/Ezike/orgs",
      "repos_url": "https://api.github.com/users/Ezike/repos",
      "events_url": "https://api.github.com/users/Ezike/events{/privacy}",
      "received_events_url": "https://api.github.com/users/Ezike/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "tdscientist",
      "id": 6681855,
      "node_id": "MDQ6VXNlcjY2ODE4NTU=",
      "avatar_url": "https://avatars1.githubusercontent.com/u/6681855?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/tdscientist",
      "html_url": "https://github.com/tdscientist",
      "followers_url": "https://api.github.com/users/tdscientist/followers",
      "following_url": "https://api.github.com/users/tdscientist/following{/other_user}",
      "gists_url": "https://api.github.com/users/tdscientist/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/tdscientist/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/tdscientist/subscriptions",
      "organizations_url": "https://api.github.com/users/tdscientist/orgs",
      "repos_url": "https://api.github.com/users/tdscientist/repos",
      "events_url": "https://api.github.com/users/tdscientist/events{/privacy}",
      "received_events_url": "https://api.github.com/users/tdscientist/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "AyoGitNg",
      "id": 13318431,
      "node_id": "MDQ6VXNlcjEzMzE4NDMx",
      "avatar_url": "https://avatars2.githubusercontent.com/u/13318431?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/AyoGitNg",
      "html_url": "https://github.com/AyoGitNg",
      "followers_url": "https://api.github.com/users/AyoGitNg/followers",
      "following_url": "https://api.github.com/users/AyoGitNg/following{/other_user}",
      "gists_url": "https://api.github.com/users/AyoGitNg/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/AyoGitNg/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/AyoGitNg/subscriptions",
      "organizations_url": "https://api.github.com/users/AyoGitNg/orgs",
      "repos_url": "https://api.github.com/users/AyoGitNg/repos",
      "events_url": "https://api.github.com/users/AyoGitNg/events{/privacy}",
      "received_events_url": "https://api.github.com/users/AyoGitNg/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "ftchirou",
      "id": 4760130,
      "node_id": "MDQ6VXNlcjQ3NjAxMzA=",
      "avatar_url": "https://avatars0.githubusercontent.com/u/4760130?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/ftchirou",
      "html_url": "https://github.com/ftchirou",
      "followers_url": "https://api.github.com/users/ftchirou/followers",
      "following_url": "https://api.github.com/users/ftchirou/following{/other_user}",
      "gists_url": "https://api.github.com/users/ftchirou/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/ftchirou/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/ftchirou/subscriptions",
      "organizations_url": "https://api.github.com/users/ftchirou/orgs",
      "repos_url": "https://api.github.com/users/ftchirou/repos",
      "events_url": "https://api.github.com/users/ftchirou/events{/privacy}",
      "received_events_url": "https://api.github.com/users/ftchirou/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "FeezyHendrix",
      "id": 27918971,
      "node_id": "MDQ6VXNlcjI3OTE4OTcx",
      "avatar_url": "https://avatars3.githubusercontent.com/u/27918971?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/FeezyHendrix",
      "html_url": "https://github.com/FeezyHendrix",
      "followers_url": "https://api.github.com/users/FeezyHendrix/followers",
      "following_url": "https://api.github.com/users/FeezyHendrix/following{/other_user}",
      "gists_url": "https://api.github.com/users/FeezyHendrix/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/FeezyHendrix/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/FeezyHendrix/subscriptions",
      "organizations_url": "https://api.github.com/users/FeezyHendrix/orgs",
      "repos_url": "https://api.github.com/users/FeezyHendrix/repos",
      "events_url": "https://api.github.com/users/FeezyHendrix/events{/privacy}",
      "received_events_url": "https://api.github.com/users/FeezyHendrix/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    },
    {
      "login": "tobydigz",
      "id": 15001016,
      "node_id": "MDQ6VXNlcjE1MDAxMDE2",
      "avatar_url": "https://avatars2.githubusercontent.com/u/15001016?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/tobydigz",
      "html_url": "https://github.com/tobydigz",
      "followers_url": "https://api.github.com/users/tobydigz/followers",
      "following_url": "https://api.github.com/users/tobydigz/following{/other_user}",
      "gists_url": "https://api.github.com/users/tobydigz/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/tobydigz/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/tobydigz/subscriptions",
      "organizations_url": "https://api.github.com/users/tobydigz/orgs",
      "repos_url": "https://api.github.com/users/tobydigz/repos",
      "events_url": "https://api.github.com/users/tobydigz/events{/privacy}",
      "received_events_url": "https://api.github.com/users/tobydigz/received_events",
      "type": "User",
      "site_admin": false,
      "score": 1.0
    }
  ]
}
answered Apr 13, 2019 by anonymous
What about this?
0 votes
There are lots of tools for this....
answered Jun 27, 2019 by Helium
Which tools can be used??
+2 votes
String prams="{"field1":"value","field2":"value2" }";

JSONObject json = new JSONObject(prams); // just this line is enough

make sure the String is alredy in proper json format as shown above
answered Jan 27 by Edd
Thanks, @Edd for your contribution.

Please register at Edureka Community and earn credits for every contribution. A contribution could be asking a question, answering, commenting or even upvoting/downvoting an answer or question.

These credits can be used to get a discount on the course. Also, you could become the admin at Edureka Community with certain points.

Cheers!
0 votes
you can use google gson.
answered Jul 11 by anonymous
• 140 points
0 votes
Here, you can use the content of Google's gson, serialization, and deserialization.
answered Jul 24 by GurwinderKaur
• 380 points

Related Questions In Java

0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 55,420 points
450 views
0 votes
2 answers
0 votes
1 answer

how to read csv file form sftp connection and store into string object in java code and convert into json.....post it using rest api

Hey, @Pooja, Before starting with anything you should ...READ MORE

answered May 12 in Java by Roshni
• 1,750 points
268 views
0 votes
2 answers

How can I convert byte array into hex string in Java?

public static String byteArrayToHex(byte[] a) { ...READ MORE

answered Aug 29, 2019 in Java by Sirajul
• 55,420 points
1,223 views
0 votes
2 answers

How an object array can be converted to string array in java?

System.arraycopy is the most efficient way, but ...READ MORE

answered Aug 8, 2018 in Java by Sushmita
• 6,890 points
183 views
0 votes
1 answer

How do I convert a String to an int in Java?

Hello @kartik, We can use the parseInt(String str) method of ...READ MORE

answered Jul 28 in Java by Niroj
• 43,660 points
24 views
0 votes
2 answers

How to convert a JSON String into Object in Java?

You could probably check out Google's Gson: ...READ MORE

answered Aug 21, 2019 in Java by Sirajul
• 55,420 points
1,249 views
0 votes
1 answer

How to convert or cast hashmap to JSON object in Java, and again convert JSON object to JSON string?

You can use: new JSONObject(map); READ MORE

answered Jun 27, 2018 in Java by Akrati
• 3,150 points
3,635 views
0 votes
1 answer

How can we return a JSON object from a Java Servlet?

response.setContentType("application/json"); // Get the printwriter object from response ...READ MORE

answered Jul 6, 2018 in Java by sharth
• 3,370 points
3,248 views
0 votes
2 answers

How do we convert JSON to Map in Java

When you don't know structure of json. ...READ MORE

answered Oct 31, 2018 in Java by Sushmita
• 6,890 points
1,594 views