Jsp use JSON Object with JSTL [duplicate] - json

This question already has answers here:
How do I use JSTL to output a value from a JSON string?
(1 answer)
Display JSON object using JSP/ JSTL tags in UI? [duplicate]
(1 answer)
How to parse JSON in Java
(36 answers)
Closed 3 years ago.
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.

Related

Powershell: How can I dynamically iterate over nested json objects? [duplicate]

This question already has answers here:
PowerShell iterate through json of key value pairs
(1 answer)
Powershell Selecting NoteProperty Type Objects From Object
(2 answers)
Closed 3 months ago.
Suppose I have something like this:
"config_service": {
"config_service_1": {
"service": "__service1__"
},
"config_service_2": {
"service": "__service2__"
}
},
I am able to grab out the parent json by doing
$jsonMappings.config_service
But how can I dynamically iterate over each json value in there and do something like, for each object within config_service, extract value of key named 'service'? When I try doing ForEach-Object it treats the config service 1 and 2 as one big object.

unmarshall json using dynamic key [duplicate]

This question already has answers here:
Golang parse a json with DYNAMIC key [duplicate]
(1 answer)
How to parse/deserialize dynamic JSON
(4 answers)
Marshal dynamic JSON field tags in Go
(1 answer)
How to Unmarshal jSON with dynamic key which can't be captured as a `json` in struct: GOlang [duplicate]
(1 answer)
Closed 4 years ago.
I'm receiving a json object that has a known-static structure inside a key that varies between 10 different values.
Consider lastname can be any in a list of 10 lastnames:
var lastnames = [...]string { "Smith", "Johnson", "Williams", "Brown", "Jones", "Miller", "Davis", "Garcia", "Rodriguez", "Wilson" }
Now, this is how the json looks:
{
(lastname here):
{
"position": value,
"user_email": value
}
}
I tried to unmarshall it using the following structs, but I only get null values:
type Inside struct {
Rol string `json:"position"`
Email string `json:"user_email"`
}
type Outside struct {
Key Inside
}
...
var outside Outside
json.Unmarshal([]byte(body), &outside)
Is it possible to unmarshall this directly without creating 10 different structs? Is there possible workaround?

How to deserialize list with mixed types? [duplicate]

This question already has answers here:
Unmarshal 2 different structs in a slice
(3 answers)
Closed 4 years ago.
How would I deserialize this JSON in Go?
{
"using": [ "jmap-core", "jmap-mail" ],
"methodCalls": [
["method1", {"arg1": "arg1data", "arg2": "arg2data"}, "#1"],
["method2", {"arg1": "arg1data"}, "#2"],
["method3", {}, "#3"]
]
}
I haven't figured out how to properly get the json module to parse the methodCalls into a type. My first idea was
type MethodCall struct {
Name string
Params map[string]string
ClientId string
}
and then to use it as a list type:
type Request struct {
Using []string
MethodCalls []MethodCall
}
But this does not work. :using" is correctly parsed, but the "methocCalls" are not. Is there a way to get Go to parse this JSON into my types?
It looks like the methodCalls that you are trying to deserialize it is an array of strings instead of a struct for MethodCall.
So, Take a look at this link that I am deserializing as an array.
If you want to use the MethodCall struct you have to change the json a little bit. Take a look at this link

from JSON object to Java Script Object that contains js function name [duplicate]

This question already has answers here:
Safely turning a JSON string into an object
(28 answers)
Closed 5 years ago.
I have this JS object:
{ validator: myValidator }
myValidator is a java JAVASCRIPT function NAME that will be declared somewhere else. I am planning to use it like:
<TableHeaderColumn dataField='status' editable={ { validator: myValidator } }>Job Status</TableHeaderColumn>
where TableHeaderColumn is a react component. So, the question is: What is the JSON string that after using JSON.parse or a similar command I will obtain the { validator: myValidator } object where myValidator is "the name of a function", not a string. This is not clear for me inclusive at the referenced solution.
To convert a JS Object to JSON, you can use json = JSON.stringify(jsObject)
To convert JSON to a JS Object, just use jsObject = JSON.parse(json)

Deserialize nested json in VB.NET [duplicate]

This question already has answers here:
VB.net JSON Deserialize
(3 answers)
Closed 6 years ago.
I am using the json.net library and I have this json file I want to deserialize:
{
"location":"/UndefinedTag/UndefinedPos/1480679543072",
"parameters":{
"SwitchPoint1":{
"SamplingRate":null,
"BitLength":16,
"BitOffset":0,
"DataType":"BooleanT"
},
"SwitchPoint2":{
"SamplingRate":null,
"BitLength":16,
"BitOffset":1,
"DataType":"BooleanT"
},
"SensorValue":{
"SamplingRate":null,
"BitLength":14,
"BitOffset":2,
"DataType":"IntegerT"
}
}
}
can anybody help ?
Thank you
Please read Deserializing complex object using Json.NET first (altough it's C#-related). In your case you need several .NET object types defined beforehand:
"parent" one holding location and parameters properties (where parameters represents collection of "named sensors")
"named sensor" representing each specialized sensor type, such as SwitchPoint1, SwitchPoint2 or SensorValue (where each "named sensor" type contains related "sensor value" property)
"sensor value" holding single sensor properties such as SamplingRate, BitLength, etc.