Deserialze Jason for particular value

Hi Everyone,

I have one jason api

{
Name : XYZ
Age : 23
},
{
Name : ABC
Age : 25
},

I wanted to deserialze age key for particular value of name coming as input.

Can anyone guide me on this ?

Regards,
Sahil Garg

we can do filtering with the help on LINQ and get the age

Your JSON snippet is incompletet. Please let us know the full JSON as we have to know if the JObjects are nested into another jobject or items of a JArray

but you can tell us if it resides within an object or are items of JArray

1 Like

It is inside JArray

Find some starter help

grafik

myJArray.ToString
@"[
{
““Name””: ““XYZ””,
““Age””: 23
},
{
““Name””: ““ABC””,
““Age””: 25
}
]"

 myJArray.Where(Function(x) x("Name").Value(Of String).Equals("ABC"))
 Enumerable.WhereEnumerableIterator<JToken> { JObject(2) { JProperty(1) { [ABC] }, JProperty(1) { [25] } } }
 myJArray.Where(Function(x) x("Name").Value(Of String).Equals("ABC")).First()("Age").Value(Of Int32)
 25

As an alternate we can also use the SelectToken method along with a filter statement
JSONPath - XPath for JSON

Hi Peter,

This is good one, but just wanted to know

I wanted to convert Age key into datatable, i have dt Variable with speicifc columns name,

Apologies if my eg is not clear.

{
Name : ABC
Age : [{“Value”:“77014”,“Code”":“26”}]
}

Age key is like this format, for that i need to deserialize it

Can u guide me if i can use any expression , so that for a particular input name i can deserialize Age key

grafik

feel free to:

  • split it into sub statements and using variables
  • adopt it to a more dynamic value grabbing e.g.

Mate,

Adding toArray one is fine, but it is not taking JArray variable, is this deserializing same ?

unclear what was meant with this.

For shortcutting it:

  • provide sample input data, reflecting in the same way your JSON data is about
  • provide expected output

Based on this we will check.

[
{
“Id”: “2331”,
“Data”: “[{“Code”:“77014”,“Modifiers”:“26”}]”
},
{
“Id”: “2332”,
“Data”: “[{“Code”:“741778”,“Modifiers”:“26”}]”
}
]

Check this one, i have j array of this api, now just finding how can i deserialize Data key for input Id ( into Data JArray), so that i can convet same in Datatable.

Output

JArray Variable which is having data of Data key, for ID 2332.

expected output / result?

1 Like

Edited same mate

vs.

this confusing us

Peter,

I just need JArray for data key.

I will loop through same to convert in datatable for specific columns.

Challenge i am facing,

I am not able to access particular block for input ID.

Adding to above,

Like a filter so that i can access particular data key

Hi Peter,

I just used this expression, getting the string of particular block which can be deserialized.

Thanks you your guidance, will ping you again if any issues come.

Regards,
Sahil Garg

have a look on this : “[{“Code”:“741778”,“Modifiers”:“26”}]”

if your JSON looks in this way we have the case that the value of Data is a serialized JObject / Dictionary

grafik
we filter to the particular JObject
then we can parse / deserialize the JSON string back to a JOBject

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.