Java JSONObject Distinct Key into List

by ameruddin jamil   Last Updated June 30, 2020 04:26 AM

Hi StackOverflow community,

I have a situation where I need to distinct the Java JSONObect key into a List. So that I can do a if else statement after that. Here is an example of my JSON Object.

  "E23": "1111",
  "E25": "5",
  "G1": {
    "b": "1",
    "c": "1"
  "G2": {
    "d": "1"
  "E2": "test pdf",
  "E3": "1",
  "E4": "1",
  "E5a": "12121991",
  "E6": "1",
  "E8": "7110",
  "E5b": 28,
  "E9": "01",
  "E1a": "1",
  "H3b": "4",
  "E24c1": "06",
  "E1b": "i",
  "H3a": "12",
  "E26a": [
  "E14a": {
    "a": "1",
    "b": "1",
    "c": "1"

The end result expected is to become like this ArrayList [E,G,H]

Just FYI, the key.chartAt(0) can be from E-I. I am thinking to looping in each of the Object and check the character at 0 and put it in the List if the List doest contain the character yet. But I think its gonna consume a lot of java processing and my function will become longer. Is there any way that I can achieve my end result without looping through all the Object.

Any advise is appreciated.

Tags : java json

Related Questions

JsonPath ignore the Debug logs on output

Updated December 10, 2018 23:26 PM