How to get same attribute of multiple objects in a JSON file using Java?

342 Views Asked by At

I have a JSON file that has stock data of different portfolios.

[
    {
        "name": "octoberportfolio", 
        "pathame": "C:\\Users\\Documents\\octoberportfolio.xlsx", 
        "stocks" :
             {
                "SWN": ["Southwestern Energy", 34, 23],
                "TSLA": ["Tesla", 4, 2100],
                "HPE": ["Hewlett Packard Enterprise", 9, 400]
            }
    },

    {
        "name": "jasonportfolio", 
        "pathame": "C:\\Users\\Documents\\Java\\jasonportfolio.xlsx", 
        "stocks" :
             {
                "AAPL": ["Apple", 34, 23],
                "MSFT": ["Microsoft", 4, 2100],
                "BAB": ["Alibaba", 9, 400]
            }

    }
]

I'd like to add the key values for "name" to an ArrayList ["octoberportfolio", "jasonportfolio"]. How would I do this? The only solution I've seen online is if there is only one object in the file.
Thanks

0

There are 0 best solutions below