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
9
votes
3 answers

Deserialize hal+json to complex model

I have the following HAL+JSON sample: { "id": "4a17d6fe-a617-4cf8-a850-0fb6bc8576fd", "country": "DE", "_embedded": { "company": { "name": "Apple", "industrySector": "IT", "owner": "Klaus Kleber", …
Thiago Lunardi
  • 749
  • 1
  • 5
  • 19
9
votes
2 answers

Deserialize an anonymous JSON array?

I got an anonymous array which I want to deserialize, here the example of the first array object [ { "time":"08:55:54", "date":"2016-05-27", "timestamp":1464332154807, "level":3, "message":"registerResourcePath ('',…
inetphantom
  • 2,498
  • 4
  • 38
  • 61
9
votes
2 answers

DateTime column type becomes String type after deserializing DataTable

I have a DataTable having two columns. ShipmentDate(DateTime) and Count(Int). after I deserialize the string I noticed the type of ShipmentDate becomes string if the first itemarray value is null. Check the below example. both the json string have…
Rashmin Javiya
  • 5,173
  • 3
  • 27
  • 49
9
votes
5 answers

Version dependent Json deserialization

I'm looking for a way to do deserialization from Json to be version dependent using the data within the Json itself. I'm targeting to use ServiceStack.Text.JsonDeserializer, but can switch to another library. For example, I'd like to define a data…
Leo Y
  • 659
  • 7
  • 22
9
votes
1 answer

Unable to tackle optional fields in JSON with Rustc-serialize

I am trying to deserialize JSON to Rust structure using rustc_serialize. The problem is that certain JSONs have some optional fields, i.e., may or may not be present. The moment the first absent field is encountered, the decoder seems to bail out…
ustulation
  • 3,600
  • 25
  • 50
9
votes
3 answers

json deserialize from legacy property names

How can I setup Newtonsoft.Json to deserialize an object using legacy member names but serialize it using the current member name? Edit: A requirement is that the obsolete member be removed from the class being serialized/deserialized. Here's an…
bboyle1234
  • 4,859
  • 2
  • 24
  • 29
9
votes
2 answers

Object de-serializing from base64 in C#

I have a class as so [Serializable] public class ExternalAccount { public string Name { get;set;} } I have converted this to JSON like so {\"Name\":\"XYZ\"} I have then base64 encoded the JSON string I then send across the wire to a web…
AdrianSean
  • 397
  • 1
  • 5
  • 21
9
votes
1 answer

Deserialization of map with integer keys using Jackson

I have to serialize a simple integer-to-string map as JSON and then read it back. The serialization is pretty simple, however since JSON keys must be strings the resulting JSON looks like: { "123" : "hello", "456" : "bye", } When I read it…
AlexR
  • 114,158
  • 16
  • 130
  • 208
9
votes
1 answer

Deserialize a json serialized CookieCollection

In my code I have to Json serialize a CookieCollection object and pass it as string, to achieve this I do like this: var json = Newtonsoft.Json.JsonConvert.SerializeObject(resp.Cookies); resulting to the following json [ { "Comment": "", …
9
votes
3 answers

Json.NET deserialization of Tuple<...> inside another type doesn't work?

Using Json.net, deserializing a type that contains a Tuple<...> doesn't work (serialization works, but deserialization doesn't): [TestMethod] public void Test() { var orig = new TupleHolder("what????", true); var json =…
Tar
  • 8,529
  • 9
  • 56
  • 127
9
votes
3 answers

How to trigger calls to .serializeWithType() of a class implementing JsonSerializable in Jackson?

This is Jackson 2.2.x. I have a class implementing JsonSerializable; there are two methods to implement for this interface, serialize() and serializeWithType(). I want to test {de,}serialization of this class, and I can trigger calls to serialize()…
fge
  • 119,121
  • 33
  • 254
  • 329
8
votes
2 answers

System.Text.Json: Get the property name in a custom converter

Deserializing using JsonSerialize.DeserializeAsync and a custom converter, e.g. public class MyStringJsonConverter : JsonConverter { public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions…
Asons
  • 84,923
  • 12
  • 110
  • 165
8
votes
1 answer

Spring boot Kafka class deserialization - not in the trusted package

I know this problem is very common, but after following different solutions I couldn't find any working one. I want to deserialize strings and also my custom class object when receiving the message in Kafka. With String is all good, but not with my…
Usr
  • 2,628
  • 10
  • 51
  • 91
8
votes
2 answers

Optional URLs causing JSON decoding to fail in Swift 4

I'm trying to figure out why using Optional URLs causes my JSON Decoding to fail using Swift 4. I've already poured over the WWDC "Whats new in Foundation" video, Apples Playground examples, and a bunch of places on the internet but haven't found a…
SN81
  • 323
  • 3
  • 13
8
votes
1 answer

Swift 4 json decoder error flickr

I am trying out the new JSONDecoder() in swift 4 and am trying to parse the following flickr API response : (https://api.flickr.com/services/rest/?api_key=api_key&method=flickr.photos.search&format=json&per_page=25&text=hello&nojsoncallback=1). …
masterqp
  • 93
  • 1
  • 4