Questions tagged [json-deserialization]

JSON deserialization is the process of converting a JSON string into an instance of an object, often a class.

JSON (Object Notation) is an efficient data encoding format that enables fast exchanges of small amounts of data between client browsers and -enabled Web services.

JSON deserialization is the process of converting a JSON string into an instance of an object, often a class. JSON encoded strings carry both structural and data information, so the instance of the object resulting from deserialization is a well-defined, data-filled object.

For example the following string:

string json_encoded_string = @"{""name"" : ""John"", ""surname"" : ""Doe"", ""age"" : 38}";

can be deserialized into an instance of the following class:

class Person
{
    public string name { get; set; }
    public string surname { get; set; }
    public int age { get; set; }
}
2322 questions
0
votes
1 answer

Could not cast or convert from System.String to Custom Object or Model

I am trying to deserialize JSON text coming from HTTP response to a particular Model. But it fails with below exception: Message=Error converting value "{"Id":"1","UserName":"RK"}" to type 'ConsoleApp5.TestData'. Inner Exception 1:…
Raj
  • 664
  • 7
  • 23
0
votes
1 answer

Is it possible to prevent the Json.Net TypeNameHandling vulnerability with a marker for trusted types?

I was reading about the vulnerability of deserializing types with Json.Net using a setting different from TypeNameHandling.None. The Json.Net docs recommend implementing a custom SerializationBinder. A simple example of a custom binder that checks…
loe
  • 83
  • 7
0
votes
2 answers

Dictionary Value contains any one of the items from a string array

I am using following model to Deserialize a JSON response from api endpoint public class APIModel { public int Prop1 { get; set; } public int Prop2 { get; set; } public int Prop3 { get; set; } …
Sebastian
  • 4,625
  • 17
  • 76
  • 145
0
votes
0 answers

Convert properties when Deserialize JSON

From an HTTP GET Request I have the following result as string: { "id": "5963363", "private": "0", "created_at": "2021-06-02 16:15:40", "release_date": "2021-06-02 16:15:40", "release_timestamp": 1622643340, "user_id": "10037997", …
Sergiu Molnar
  • 865
  • 1
  • 11
  • 22
0
votes
0 answers

How to inject specific property value while Json deserialization

I need to inject the specific property value to object that is being deserialize using JsonConvert.DeserializeObject method. for example I have a class public class Employee { public int EmployeeID {get; set;} public string Name {get; set;} …
Neeraj Kumar Gupta
  • 2,157
  • 7
  • 30
  • 58
0
votes
1 answer

Cannot Deserialize JSON String in C#

I have the following models: public class InputFile { public string Path { get; set; } // absolute path of file public string Content { get; set; } // full content of the json file } and public class InputModel { public List
0
votes
1 answer

Uno Platform WASM SignalR deserialization issues

I have a SignalR service and an Uno Platform WASM Client (with Prism). I want to call a hub method, which returns a model. The problem is, i have two identical models (Properties, Methods, etc.) but the client can only receive one of them upon…
0
votes
1 answer

Deserialising JSON made up of various models C#

I'm trying to work out how to deserialise a JSON response that can be made up of single or multiple models, so for instance, I have the following URL and Response from that endpoint: https://api.site.com/products?query=fruit Which would return…
MrDKOz
  • 207
  • 2
  • 11
0
votes
0 answers

Is it possible to serialise a Func or Action to JSON in .Net Core

I was wondering if it is possible to serialise a Func or Action to JSON using either Json.Net or System.Text.Json in .Net Core with C#. I believe this was possible in .Net Framework but haven't found a way to do this in Core. It's not something I…
SBFrancies
  • 3,987
  • 2
  • 14
  • 37
0
votes
0 answers

How to configure kafka deserializer so that it let pass only keys with values?

I have a kafka consumer which does the deserialization of JSON. I get big messages like : { data1: [], data2: ["content"], data3: null, data4: [], data5: "foo", data6: "", data7: [""], data8: [null], ... dataX:…
Maik
  • 310
  • 1
  • 11
0
votes
1 answer

How to dynamically parse only part of the JSON

I have the next issue: I receive a lot of JSONs in different formats. I need to process only part of these documents. I tried to use Newtonsoft.Json.Schema nuget, but got the next problem: JSON how to don't parse additional properties Can you…
Hanna Holasava
  • 192
  • 1
  • 15
0
votes
0 answers

Serialize/Deserialize complex Dictionary by Newtonsoft JSON gives me errors while deserializing

My JSON looks like: [ { "Key": { "PatientName": "Hans Gerd", "Alter": 81, "Geschlecht": "M", "Zimmernummer": 1, "PatientenLiegeplatz": 0, "IsDummyData": false }, "Value": { "Puls": 0, …
Xelia
  • 1
  • 2
0
votes
0 answers

Deserializing Jackson object where key is value inside larger object

I have a rather large JSON object (this is a subset) I'm trying to parse: { "items": [ { "Name": "Wallet", "tags": [ "wallet", "cardholder" ], "features": { "material": { "location":…
Nho Jotom
  • 391
  • 1
  • 3
  • 7
0
votes
0 answers

Parsing a JSON object with dynamic content: what is the best way to do it with low cyclomatic complexity?

I have a service that returns an array of objects in this form: { result: [ { objectId: "id", type: "objectType", content: { ... } }, ... ] } The content depends on the object type. I've…
Kappei
  • 714
  • 2
  • 15
  • 34
0
votes
0 answers

Class Marked with @JsonRootName is not mapped during deserialization

I'm using RestTemplate to call an external API. Here is the result of the API call : { "results": [ { "code": "UDE", "usergroups": [ { "name": "Some name", …