Linked Questions
39 questions linked to/from JSON.Net throws StackOverflowException when using [JsonConvert()]
0
votes
0
answers
145
views
How to use the NewtonSoft JsonConverterAttribute and JToken.FromObject() without calling the JsonConverter recursively [duplicate]
I have taken the code from this example and changed a few things:
remove the custom constructor and hardcode the CanConvert type.
removed the converter from the calls JsonConvert.SerializeObject() ...
1
vote
0
answers
27
views
Serializing C# class with extra fields plus normal properties in a nested object [duplicate]
I have the following classes:
public class Base
{
}
public class A : Base
{
public Base AField { get; set; }
}
public class B : Base
{
public int I { get; set; }
public int I2 { get; set;...
312
votes
12
answers
214k
views
Does JSON syntax allow duplicate keys in an object?
Is this valid json?
{
"a" : "x",
"a" : "y"
}
http://jsonlint.com/ says yes.
http://www.json.org/ doesn't say anything about it being forbidden.
But ...
77
votes
11
answers
154k
views
Json.NET serialize object with root name
In my web app I'm using Newtonsoft.Json and I have following object
[Newtonsoft.Json.JsonObject(Title = "MyCar")]
public class Car
{
[Newtonsoft.Json.JsonProperty(PropertyName = "name")]
...
15
votes
1
answer
23k
views
Json.net deserialization null guid case
I'm deserializing an object using Json.NET that contains a private field of type Guid and a public property for that field. When the value for my Guid is null in my json I want to assign Guid.Empty to ...
17
votes
1
answer
9k
views
Json.NET custom serialization with JsonConverter - how to get the "default" behavior
I have a JsonConverter for my class DataType.
I would like to do some special handling when plain string used in Json as the value of a property of type DataType. In the case where the value is a "...
7
votes
1
answer
4k
views
Selectively use default JSON converter
I use the following in my Web API project's Startup.cs to JSON-serialize Enums into strings:
// Configure JSON Serialization
var jsonSerializationSettings = GlobalConfiguration.Configuration....
4
votes
1
answer
4k
views
NewtonSoft JsonConverter - Access other properties
I have a need to format the output json of a decimal to a currency, with the culture specified my the object I am serializing, the object could be nested so I cannot preset the option in the ...
8
votes
1
answer
2k
views
How can I serialise PSObjects in C# with JSON.NET?
I am writing a Cmdlet and need to pass object structures into an API client that may contain PSObjects. Currently, these serialise as a JSON string containing CLIXML. Instead, I need it to be treated ...
4
votes
1
answer
4k
views
How to deserialize generic interface to generic concrete type with Json.Net?
I have below interface:
public interface IInterface<out M>
{
M Message { get; }
string Str { get; }
}
And its implementation:
public class Implementation<M> : IInterface<M>
{...
6
votes
2
answers
1k
views
Json.NET different json structure, based on enum value
I need to convert my class to JSON and I use Json.NET. But I can have different JSON structures, like:
{
name: "Name",
type: "simple1",
value: 100
};
or
{
name: "Name",
type: {
...
1
vote
1
answer
2k
views
StackOverflow exception when using custom JsonConverter and custom ContractResolver
My requirement is use JsonProperty during de-serializing and ignore JsonProperty during serialization. My model,
[JsonConverter(typeof(JsonPathConverter))]
public class FacebookFeed
{
public ...
3
votes
1
answer
3k
views
Call default JsonSerializer in a JsonConverter for certain value type arrays
I'm trying to achieve roughly what's described here:
Recursively call JsonSerializer in a JsonConverter
In short; To examine a value being deserialised, then either consume it in my own code, or ...
1
vote
2
answers
2k
views
Newtonsoft JSON converter serialzation: in writeJson(), how to modify value and avoid recurse into self?
I want to slightly tweak serialization result in a non-intrusive way.
For example, I want this class:
class A { int va; }
to be modified like this { va: value } -> { va: value * 2 }
So I tried to ...
3
votes
2
answers
862
views
Generic method of modifying JSON before being returned to client
I'm after a generic method that allows me to modify the JSON of an object being returned to the client, specifically the removal of certain properties in returned objects. Similar to what is suggested ...