0

I know this topic was discussed pretty often and I guess it is not a diffucult thing. I want to use a JSON Object from my session in a JSP. The Object has the following structur:

 {

"addedUsers":[
    {
        "city":"Los Angeles",
        "name":"Doe",
        "forname":"John",
        "title":"Dr.",
        "userId":2
    }
],
"allUsers":[
    {
        "city":"Los Angeles",
        "name":"Doe",
        "forname":"John",
        "title":"Dr.",
        "userId":2
    },
    {
        "city":"New York",
        "name":"Peter",
        "forname":"Parker",
        "title":"Dr.",
        "userId":3
    }
]

}

Now I want to grab the Objects by name for example doing a for each on the "addedUsers" Object and grab the properties. It is important not just to iterate over the whole Object. I have to call them by name.

FishingIsLife
  • 1,972
  • 3
  • 28
  • 51
  • Just convert JSON string to a Java object? This should already have been answered in every "discussion" which you found. – BalusC May 14 '19 at 10:10
  • I thought it might be possible with jstl? I'm completely new to frontend development and I don't know what's the best way. I want to use the data to fill a html table – FishingIsLife May 14 '19 at 10:11
  • Sorry for asking again. I thought it might be possible without using third party. So the best way would be to create Java Objects from the JSON and use them instead of the JSON in the jsp? – FishingIsLife May 14 '19 at 10:26
  • JSTL/EL can only access properties of Java objects, not JSON strings. That's a fact. Hence you need to convert a proprietary JSON string to a normal Java object. What's the deal with "using third party"? Why the apparent aversion? You can of course also write all that code yourself to convert JSON string to Java object, but that would only end up in code duplication and possibly brittle and unsafe code depending on your software development experience. You might even end up wasting way much more time than you'd expect. You'd much like to favor an existing and well-tested library for this. – BalusC May 14 '19 at 11:56

0 Answers0