I am getting a response String from server like below
{
\"name\": \"Json\",
\"detail\": {
\"first_name\": \"Json\",
\"last_name\": \"Scott\",
If you don't mind adding a dependency, you can use JsonPath.
import com.jayway.jsonpath.JsonPath;
String firstName = JsonPath.read(rawJsonString, "$.detail.first_name");
"$" specifies the root of the raw json string and then you just specify the path to the field you want. This will always return a string. You'll have to do any casting yourself.
Be aware that it'll throw a PathNotFoundException at runtime if the path you specify doesn't exist.