'How to Extract Keys from JSON Array and store it into Arraylist in java [duplicate]

I have this json file-

[
  {
    "symbol": "AAPL",
    "quantity": 100,
    "tradeType": "BUY",
    "purchaseDate": "2019-01-02"
  },
  {
    "symbol": "MSFT",
    "quantity": 10,
    "tradeType": "BUY",
    "purchaseDate": "2019-01-02"
  },
  {
    "symbol": "GOOGL",
    "quantity": 50,
    "tradeType": "BUY",
    "purchaseDate": "2019-01-02"
  }
]

and I need to prepare the list of all symbols for example if

[{ "symbol": "MSFT"}, { "symbol": "AAPL"}, { "symbol": "GOOGL"}]

then output should be-

["MSFT", "AAPL", "GOOGL"]

Can anyone help me how I can extract "symbol" field value and store above output in list?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source