This is simple code to do it, I avoided all checks but this is the main idea.

 public String parse(String jsonLine) {
    JsonElement jelement = JsonParser.parseString(jsonLine);
    JsonObject  jobject = jelement.getAsJsonObject();
    jobject = jobject.getAsJsonObject("data");
    JsonArray jarray = jobject.getAsJsonArray("translations");
    jobject = jarray.get(0).getAsJsonObject();
    String result = jobject.get("translatedText").getAsString();
    return result;
}

To make the use more generic - you will find that Gson's javadocs are pretty clear and helpful.

Answer from MByD on Stack Overflow
🌐
Jenkov
jenkov.com › tutorials › java-json › gson-jsonparser.html
GSON - JsonParser
January 27, 2021 - The GSON JsonParser is GSON's tree parser which parses JSON into a tree structure (of Java objects). This GSON JsonParser tutorial shows you how to use the JsonParser in practice.
🌐
HowToDoInJava
howtodoinjava.com › home › gson › gson jsonparser
Gson JsonParser (with Examples) - HowToDoInJava
April 4, 2023 - Java program to parse JSON into JsonElement (and JsonObject) using JsonParser and fetch JSON values using keys. import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; public class JsonElementExample { public static void main(String[] args) { String json = "{'id': 1001, " + "'firstName': 'Lokesh'," + "'lastName': 'Gupta'," + "'email': 'howtodoinjava@gmail.com'}"; JsonElement jsonElement = JsonParser.parseString(json); JsonObject jsonObject = jsonElement.getAsJsonObject(); System.out.println( jsonObject.get("id") ); System.out.println( jsonObject.get("firstName") ); System.out.println( jsonObject.get("lastName") ); System.out.println( jsonObject.get("email") ); } }
🌐
GitHub
github.com › google › gson › blob › main › gson › src › main › java › com › google › gson › JsonParser.java
gson/gson/src/main/java/com/google/gson/JsonParser.java at main · google/gson
import com.google.gson.stream.MalformedJsonException; import java.io.IOException; import java.io.Reader; import java.io.StringReader; · /** * A parser to parse JSON into a parse tree of {@link JsonElement}s. * * <p>The JSON data is parsed in {@linkplain JsonReader#setStrictness(Strictness) lenient mode}. * * <p>Here's an example of parsing from a string: * * <pre> * String json = "{\"key\": \"value\"}"; * JsonElement jsonElement = JsonParser.parseString(json); * JsonObject jsonObject = jsonElement.getAsJsonObject(); * </pre> * * <p>It can also parse from a reader: * * <pre> *
Author   google
🌐
GitHub
google.github.io › gson › UserGuide.html
Gson User Guide | gson
Use Gson’s parser API (low-level streaming parser or the DOM parser JsonParser) to parse the array elements and then use Gson.fromJson() on each of the array elements.This is the preferred approach. Here is an example that demonstrates how to do this. Register a type adapter for Collection.class ...
🌐
Baeldung
baeldung.com › home › json › convert string to jsonobject with gson
Convert String to JsonObject with Gson | Baeldung
May 5, 2025 - First, we’ll need to include ... The first approach we’ll examine for converting a JSON String to a JsonObject is a two-step process that uses the JsonParser class....
🌐
HowToDoInJava
howtodoinjava.com › home › gson › gson jsonreader
Gson JsonReader - Streaming JSON Parser - HowToDoInJava
April 3, 2023 - Learn to work with Gson JsonReader class which is a pull-based streaming JSON parser. It helps in reading a JSON as a stream of tokens. 1. JsonReader Read More : Streaming parser of XML 2. Tokens In streaming mode, every JSON data is considered ...
🌐
Tabnine
tabnine.com › home page › code › java › com.google.gson.jsonparser
com.google.gson.JsonParser.parse java code examples | Tabnine
Gson gson = new Gson(); JsonParser parser=new JsonParser(); //object arr example JsonArray arr=parser.parse(mPrefs.getString("myArrKey", null)).getAsJsonArray(); events=new Event[arr.size()]; int i=0; for (JsonElement jsonElement : arr) ...
Find elsewhere
🌐
Javadoc.io
javadoc.io › doc › com.google.code.gson › gson › latest › com.google.gson › com › google › gson › JsonParser.html
JsonParser - gson 2.13.2 javadoc
Bookmarks · Latest version of com.google.code.gson:gson · https://javadoc.io/doc/com.google.code.gson/gson · Current version 2.13.2 · https://javadoc.io/doc/com.google.code.gson/gson/2.13.2 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/com.go...
🌐
ZetCode
zetcode.com › java › gson
Java Gson - JSON serialization and deserialization in Java with Gson
October 10, 2024 - Gson tutorial shows how to work with JSON in Java using Gson library. We use three different Gson APIs to work with JSON.
🌐
HowToDoInJava
howtodoinjava.com › home › gson › gson tutorial: read and write json with examples
Gson Tutorial: Read and Write JSON with Examples
August 27, 2023 - Excluding Fields From Serialization and Deserialization – Gson supports numerous mechanisms for excluding top-level classes, fields and field types. Learn how to use them. JsonReader – Streaming JSON parser – Learn to read a JSON string or file as a stream of JSON tokens. JsonParser, ...
🌐
Jenkov
jenkov.com › tutorials › java-json › gson.html
GSON - Java JSON Tutorial
February 18, 2016 - Google developed GSON for internal use but open sourced it later. GSON it reasonably easy to use, but in my opinion not as elegant as Jackson or Boon (the winner in my opinion). In this GSON tutorial I will take you through how to use GSON to parse JSON into Java objects, and serialize Java objects into JSON.
🌐
Javadoc.io
javadoc.io › doc › com.google.code.gson › gson › 2.6.2 › com › google › gson › JsonParser.html
JsonParser - gson 2.6.2 javadoc
Bookmarks · Latest version of com.google.code.gson:gson · https://javadoc.io/doc/com.google.code.gson/gson · Current version 2.6.2 · https://javadoc.io/doc/com.google.code.gson/gson/2.6.2 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/com.goog...
🌐
Twilio
twilio.com › en-us › blog › developers › tutorials › building-blocks › java-json-with-gson
Two ways to use Gson for JSON in Java | Twilio
June 13, 2025 - JsonParser parser = new JsonParser(); JsonElement neoJsonElement = parser.parse(SourceData.asString()); ... I find this code quite readable, although I don’t really think I need to know about the distinction between a JsonElement and a JsonObject ...
🌐
HowToDoInJava
howtodoinjava.com › home › gson › gson – parse json array to java array or list
Gson - Parse JSON Array to Java Array or List
April 4, 2023 - Learn to use Google GSON library to deserialize or parse a JSON array to a Java array or List object. It’s worth mentioning that JSON has only array datatype. Java has both – arrays and lists.
🌐
Baeldung
baeldung.com › home › json › using static methods instead of deprecated jsonparser
Using Static Methods Instead of Deprecated JsonParser | Baeldung
June 20, 2024 - Efficient JSON parsing is one of the most important tasks in Java programming when it comes to data manipulation and communication. The Gson library offers a versatile JsonParser class to simplify the conversion process.
Top answer
1 of 5
21

you could try reading the gson value like this:

try {
      AssetManager assetManager = getAssets();
  InputStream ims = assetManager.open("file.txt");

  Gson gson = new Gson();
  Reader reader = new InputStreamReader(ims);

  GsonParse gsonObj = gson.fromJson(reader, GsonParse.class);

     }catch(IOException e) {
       e.printStackTrace();
 }

Assuming that you are just receiving this one block and not a list. And also this data is currently in a file in the assets folder. You can change it to the stream you want to read it from.

The class you use should look like:

GsonParse.class

public class GsonParse {
 @SerializedName("count")
 private String count;

 @SerializedName("colbreak")
 private String colbreak;

 @SerializedName("name")
 private String name;

 @SerializedName("score")
 private String score;

 @SerializedName("Words")
 private List<Words> mWords = new ArrayList<Words>();

 @SerializedName("seek")
 private String seek;

public String getCount() {
    return count;
}

public void setCount(String count) {
    this.count = count;
}

public String getColbreak() {
    return colbreak;
}

public void setColbreak(String colbreak) {
    this.colbreak = colbreak;
}

private String getName() {
    return name;
}

private void setName(String name) {
    this.name = name;
}

public String getScore() {
    return score;
}

public void setScore(String score) {
    this.score = score;
}

public List<Words> getmWords() {
    return mWords;
}

public void setmWords(List<Words> mWords) {
    this.mWords = mWords;
}

public String getSeek() {
    return seek;
}

public void setSeek(String seek) {
    this.seek = seek;
}
}

Words.class

public class Words {
@SerializedName(value ="count")
private String count;
@SerializedName(value="word")
private String word;
@SerializedName(value="score")
private String name;
@SerializedName(value="Words")
private String words;
@SerializedName(value="seek")
private String seek;

    public String getCount() {
    return count;
}
public void setCount(String count) {
    this.count = count;
}
public String getWord() {
    return word;
}
public void setWord(String word) {
    this.word = word;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getWords() {
    return words;
}
public void setWords(String words) {
    this.words = words;
}
public String getSeek() {
    return seek;
}
public void setSeek(String seek) {
    this.seek = seek;
}
}

there is a parameter missing in words.class, you could add it .

GSON does not directly support UTF-8 characters. so when receiving the response using http, you will have to convert that to utf-8 form in the response of http itself.

you could try using:

String jsonString = new Gson().toJson(objectToEncode);
byte[] utf8JsonString = jsonString.getBytes("UTF8");
responseToClient.write(utf8JsonString, 0, utf8JsonString.Length);
2 of 5
9

Hello use below gradle lib

compile 'com.google.code.gson:gson:2.2.4'

Json Class

import java.util.List;
public class GsonParse{

/**
 * count : 12
 * colbreak : 1
 * name : unary rels
 * score : 9090
 * Words : [{"count":6,"word":"prp_għaċ-","name":"prp_għaċ-","score":9.1,"Words":"kol","seek":2231297}]
 * seek : 0
 */

private String count;
private int colbreak;
private String name;
private String score;
private int seek;
/**
 * count : 6
 * word : prp_għaċ-
 * name : prp_għaċ-
 * score : 9.1
 * Words : kol
 * seek : 2231297
 */

private List<WordsBean> Words;

public String getCount() {
    return count;
}

public void setCount(String count) {
    this.count = count;
}

public int getColbreak() {
    return colbreak;
}

public void setColbreak(int colbreak) {
    this.colbreak = colbreak;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getScore() {
    return score;
}

public void setScore(String score) {
    this.score = score;
}

public int getSeek() {
    return seek;
}

public void setSeek(int seek) {
    this.seek = seek;
}

public List<WordsBean> getWords() {
    return Words;
}

public void setWords(List<WordsBean> Words) {
    this.Words = Words;
}

public static class WordsBean {
    private int count;
    private String word;
    private String name;
    private double score;
    private String Words;
    private int seek;

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public String getWords() {
        return Words;
    }

    public void setWords(String Words) {
        this.Words = Words;
    }

    public int getSeek() {
        return seek;
    }

    public void setSeek(int seek) {
        this.seek = seek;
    }
}

}

Calling API put response in below code and Retrive Data

GsonParse gsonparse = gson.fromJson(response, GsonParse.class);
//gsonparse.getWords() // It will returns list of Words
//Also do loop and get more data using data
gsonparse.getColbreak();
gsonparse.getSeek();
for (GsonParse.WordsBean data:gsonparse.getWords())
{

    data.getName();

}

hope it will help to you..