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

JSON parse error: Missing a name for object member

I'm new to json and trying to get a basic example working. My http request returns {'username': '1'},{'username': '1'}. I'm confused as to what valid json looks like but also how to get it into a string variable to deserialize. Since ToJson…
lawrencehagman
  • 471
  • 1
  • 3
  • 16
12
votes
4 answers

Json.NET deserialize or serialize json string and map properties to different property names defined at runtime

I have the following JSON string: { "values": { "details": { "property1": "94", "property2": "47", "property3": "32", "property4": 1 }, count: 4 } } I am going to…
Avi K.
  • 1,734
  • 2
  • 18
  • 28
12
votes
3 answers

How to deserialize a float value with a localized decimal separator with Jackson

The input stream I am parsing with Jackson contains latitude and longitude values such as here: { "name": "product 23", "latitude": "52,48264", "longitude": "13,31822" } For some reason the server uses commas as the decimal separator…
JJD
  • 50,076
  • 60
  • 203
  • 339
11
votes
3 answers

Cannot deserialize from Object value (no delegate- or property-based Creator) using Jackson

I'm trying to deserialise below JSON payload with Jackson: {"code":null,"reason":"subscription yet available","message":"{ Message:\"subscription yet available\", SubscriptionUID:\"46b62920-c519-4555-8973-3b28a7a29463\" }"} but I'm getting this…
Scripta14
  • 463
  • 2
  • 8
  • 22
11
votes
1 answer

Jackson deserialization error: no String-argument constructor/factory method to deserialize from String value

I am trying to deserialize the following JSON { "deliverLumpSum": 0.0, "faxQId": "{\"type\":\"TAKEAWAY\",\"data\":{\"orderId\":\"AWSWD-AWSAW\",\"orderKey\":\"DERS34S32SD\"}}" } With help of the following custom deserializer public class…
user1167253
  • 813
  • 1
  • 11
  • 27
11
votes
3 answers

Get JSON key name using GSON

I have a JSON array which contains objects such as this: { "bjones": { "fname": "Betty", "lname": "Jones", "password": "ababab", "level": "manager" } } my User class has a username which would require the…
Ahmad
  • 603
  • 1
  • 8
  • 17
11
votes
2 answers

Why does this anonymous type not deserialize properly using JsonConvert.DeserializeAnonymousType?

I have the JSON string: {"response":{"token":"{\"token\":\"123\",\"id\":191}"}} And then I have the following code to Deserialize it, but it is returning null: var def = new { token = new { token = string.Empty, id= string.Empty…
xaisoft
  • 3,343
  • 8
  • 44
  • 72
10
votes
2 answers

Deserialize multiple json objects from a stream using Newtonsoft Json

I am reading a NetworkStream for json string and then deserializing it using Newtonsoft.Json. Sometimes, two json objects could be sent back-to-back and read at the same time on the stream. But the Newtonsoft.Json serializer gives me only one…
Xpleria
  • 5,472
  • 5
  • 52
  • 66
10
votes
1 answer

aspnet:MaxJsonDeserializerMembers vs maxRequestLength

I am running into errors like The JSON request was too large to be deserialized.. Quick search on stackoverflow tells you that you should set appSetting aspnet:MaxJsonDeserializerMembers to be higher to fix the issue. However, the msdn documentation…
KnightFox
  • 3,132
  • 4
  • 20
  • 35
10
votes
1 answer

How to deserialize collection with different types?

I have a JSON feed that looks like this (I removed some fields that aren't necessary for this example): { "total_count": 2, "num_pages": 1, "current_page": 1, "balance": { "amount": "0.00001199", "currency": "BTC" }, …
Leon Cullens
  • 12,276
  • 10
  • 51
  • 85
10
votes
1 answer

Using ServiceStack.Text to deserialize a json string to object

I have a JSON string that looks like: "{\"Id\":\"fb1d17c7298c448cb7b91ab7041e9ff6\",\"Name\":\"John\",\"DateOfBirth\":\"\\/Date(317433600000-0000)\\/\"}" I'm trying to deserialize it to object (I'm implementing a caching interface) The trouble I'm…
Alex
  • 37,502
  • 51
  • 204
  • 332
9
votes
2 answers

Deserialize into a case-insensitive dictionary using System.Text.Json

I'm trying to deserialize json into an object with a property of type Dictionary. I specify the comprarer for the Dictionary as StringComparer.OrdinalIgnoreCase. Here's this class: class DictionaryTest { public…
Ben
  • 538
  • 1
  • 9
  • 24
9
votes
1 answer

How to identify the missing type id in Jackson error?

I am using Jackson to write JSON to a text file, the JSON represents 2 classes inherited from an abstract class but the error also occurs irrespective of whether both or either/or classes are used. The JSON appears to be written correctly but on…
james
  • 113
  • 1
  • 1
  • 10
9
votes
2 answers

How to load polymorphic objects in appsettings.json

Is there any way how to read polymorphic objects from appsettings.json in a strongly-typed way? Below is a very simplified example of what I need. I have multiple app components, named Features here. These components are created in runtime by a…
Karel Kral
  • 5,297
  • 6
  • 40
  • 50
9
votes
3 answers

How to inject dependency into Jackson Custom deserializer

I want to enable a custom jackson deserializer of some fields of type String. The deserializer also needs to be injected with a guice based dependency bean. SampleCode below: public class CustomDeserializer extends StdDeserializer { …
Keen Sage
  • 1,899
  • 5
  • 26
  • 44