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
8
votes
1 answer

JSON deserialize , Error : null to value type, how to know exact property causing error?

In my C# code, I'm trying to deserialize a JSON with 100s of properties (complex, primitive, derived) and I'm getting an error Cannot convert null to a value type. Though I finally knew which property is causing a problem by manual…
anoop
  • 3,812
  • 2
  • 16
  • 28
8
votes
1 answer

How can I use Json.NET to deserialize objects by reference, when using a custom format for the reference?

I have JSON in the following format: { "users": [ { "first_name": "John", "last_name": "Smith", "vet": [ "FOO", "VET-1" ], "animals": [ [ "FOO", "ANIMAL-22" ] ] }, { …
Ben Jenkinson
  • 1,806
  • 1
  • 16
  • 31
8
votes
4 answers

gson - deserialzing objects containing lists

I am new to gson and am trying to work out how to deserialise a list within an object. The error message hints at creating an InstanceCreator for Player, which I did. But when implemented, I was finding that the deserialised object contained a list…
darren_c
  • 81
  • 1
  • 4
8
votes
4 answers

Deserialize nested object with GSON

I'm trying to deserialize the following structure { meta: { keywords: [a, b, c, d]} ... } other valid structures are { meta: { keywords: "a,b,c,d"} ... } and { meta: {keywords: "a"} ...} I have this classes public class Data { …
Osarez
  • 366
  • 1
  • 2
  • 10
8
votes
1 answer

How to change all keys to lowercase when parsing JSON to a JToken

I have a string of JSON and the keys have uppercase and lowercase characters: {"employees":[ {"FIrstName":"John", "LASTname":"Doe"}, {"FIRSTNAME":"Anna", "LaSTNaME":"Smith"}, {"firstName":"Peter", "lastName":"Jones"} ]} I want convert…
Rafi
  • 2,433
  • 1
  • 25
  • 33
8
votes
1 answer

Deserializing attributes of same name but different types in Jackson?

I have a REST API which returns a JSON response as: { "channel" : "JHBHS" } and sometimes it returns: { "channel": { "id": 12321, "name": "Some channel" } } I have a POJO like: public…
Ram Patra
  • 16,266
  • 13
  • 66
  • 81
8
votes
3 answers

How can I get Jackson to deserialize into my own Array implementation

Given my own array implementation MyArray, how can I make it known to Jackson, so that it is able to deserialize from a JSON Array into MyArray? So far I am only getting this exception: com.fasterxml.jackson.databind.JsonMappingException: Can…
tyrondis
  • 3,364
  • 7
  • 32
  • 56
8
votes
1 answer

Json.Net calls property getter during deserialization of list, resulting in duplicate items

I'm using json.net to implement the memento pattern for a winform application. I'm using the memento to rollback an object on a failed database transaction. The problem I'm getting is that when deserializing the memento, the getter is called…
Preston S
  • 2,751
  • 24
  • 37
8
votes
1 answer

Creating a JMS Serializer handler in symfony2

I tried to follow the related documentation, here: http://jmsyst.com/libs/serializer/master/configuration here http://jmsyst.com/libs/serializer/master/handlers and…
Flip
  • 4,778
  • 1
  • 34
  • 48
8
votes
2 answers

Jackson - Deserialize nested JSON

I have a JSON string which will be of the following format: { "response": { "execution_status": "ready", "report": { "cache_hit": true, "created_on": "2013-07-29 08:42:42", "fact_cache_error": null, …
Anand
  • 1,791
  • 5
  • 23
  • 41
7
votes
1 answer

Simple JSON deserialization of records incorrect (Delphi Sydney [10.4.1])

What happened to the JSON deserializer of Delphi Sydney (10.4.1)? After the migration from Delphi Seattle to Sydney, the standard marshal has problems with the deserialization of simple records. Here is an example and simplified representation of my…
7
votes
1 answer

How to deserialise enumeration with string representation?

I would like to create a class, which has an enumeration as an attribute. This enumeration should have a string representation that shows up as human-readable value when dumping the instance of the class that uses the enum attribute as a JSON…
7
votes
3 answers

JsonMappingException occurs while converting object to JSON string - org.apache.avro.AvroRuntimeException: Not an array:

While converting Java object to JSON string, I'm facing JsonMappingException. Below is the complete exception message. com.fasterxml.jackson.databind.JsonMappingException: Not an array:…
Nicolas
  • 554
  • 2
  • 11
  • 27
7
votes
3 answers

Parse JSON String to JsonObject/Map/MutableMap in Kotlin

I'm fairly new to Kotlin and I'm having trouble manipulating a basic JSON string to access its contents. The JSON string looks like…
Fdo
  • 1,053
  • 4
  • 15
  • 38
7
votes
1 answer

Jackson Deserializer delegate to next applicable deserializer

I have an external service which I use to query some data. The data will be in one of two formats (first of which is kind of "legacy", but needs to be supported): { "foo": "John Smith" } or { "foo": { "name": "John Smith", …
user900547