Java Language JSON in Java JSON To Object (Gson Library)


Lets assume you have a class called Person with just name

private class Person {
    public String name;

    public Person(String name) { = name;


Gson gson = new Gson();
String json = "{\"name\": \"John\"}";

Person person = gson.fromJson(json, Person.class);
System.out.println(; //John

You must have gson library in your classpath.