This tag can be used when you want to convert any text, objects or other formats into a JSON object,or if you want to transform a JSON object into something else.
Questions tagged [jsonconvert]
207 questions
2
votes
0 answers
Overriding [JsonConverter(typeof(UsualConverter)] class attribute
Test on Fiddle: https://dotnetfiddle.net/RyxMjm
using NewtonSoft.Json;
Let SomeClass be a library class that needs a custom json converter. The library it comes in provides the custom json converter, UsualConverter, and links the converter to the…

bboyle1234
- 4,859
- 2
- 24
- 29
2
votes
3 answers
How to convert a LinkedHashMap> into a JSONObject?
I'm new at JSONObject and I'm trying to convert a LinkedHashMap> into a json file.
The map is structured in this way:
"element_one", {Node1, Node2, etc...}
"element_two", {Node1, Node2, etc...}
Every Node has two properties:…

Simone Colnaghi
- 682
- 8
- 11
2
votes
2 answers
Custom Model Binder AspNet Core 2.2 for complex nested property
I have an Angular client and create a POST request with this body:
{"Name":"example","Currency":"EUR"}
I Use Odata protocol and my Controller is:
[HttpPost, ODataRoute("Templates")]
public IActionResult Insert([FromBody] Template value)
…

Mr Wolf
- 31
- 7
2
votes
1 answer
C# - OutOfMemoryException saving a List on a JSON file
I'm trying to save the streaming data of a pressure map.
Basically I have a pressure matrix defined as:
double[,] pressureMatrix = new double[e.Data.GetLength(0), e.Data.GetLength(1)];
Basically, I'm getting one of this pressureMatrix every 10…

Victor P.
- 97
- 10
1
vote
1 answer
Why can't I deserialize string Into a model?
I'm using a HTTP client to get a string and picking out my json from that and converting back to a string to deserialize it into a List of "Spots" but can't get it to to work
I've tried changing the DeserializeObject type to every mix of "List,…

Corey673
- 23
- 4
1
vote
1 answer
How to prevent JsonReaderException when json is not valid in JsonConvert.DeserializeObject
I've a method that deserialize string into a type.
var data = JsonConvert.DeserializeObject("invalid json");
If string is not valid, JsonReaderException occurring.
I want to return default value of TestData (null) when string is not valid…

Farhad Zamani
- 5,381
- 2
- 16
- 41
1
vote
2 answers
System.Text.Json: How to convert from "true" to boolean
If I receive JSON which is beyond my control, which has a property as follows.
{"allow":"true"}
and I want that to map to a bool property in C#.
I saw that I can do similar for numbers using the…

Yossi Sternlicht
- 740
- 1
- 6
- 17
1
vote
1 answer
C# JsonConvert REST API Json to Class
I've started learning C# and I've been going crazy because of this:
So I've read this of an online API to a string (ORIGINAL URL:…

Vilenzo
- 27
- 4
1
vote
2 answers
Take the data from json string and pass children nodes to the first level with navigation path
Hello I have this example json string:
{
"property1":"value1",
"property2":"value2",
"anotherObject":{
"property1":"anothervalue1",
"property2":"anothervalue2",
"anotherOfAnother":{
"property1":"value1"
}
…

Jose David
- 23
- 4
1
vote
2 answers
JsonConvert.SerializeXmlNode() add escape charactor
there is a xml message:
12345\n67890
98765\\4321
I need to convert the xml to json:
String strXmlData = xmlHelper.SelectSingleNode(xml,"//Data").OuterXML
XmlDocument xmlDoc = new…

dmd
- 337
- 1
- 4
- 17
1
vote
1 answer
How to convert JsonElement to a Int or other primitive types
I have c# webapi on .net 6.0. And I am getting postdata from client into param_class into _input. the class is like following:
public class param_class
{
public string? name { get; set; }
public object? value { get; set; }
}
client sends…

Orgil
- 187
- 3
- 13
1
vote
1 answer
Why is JsonConverter attribute not inherited from interface?
In have the following code:
interface ITyped where TypeEnum : Enum, struct
{
[JsonConverter(typeof(JsonStringEnumConverter))]
public TypeEnum Type { get; }
}
class Foo : ITyped
{
public Foo(FooType type) { Type =…

Kjara
- 2,504
- 15
- 42
1
vote
0 answers
How to reset an Utf8JsonReader to its starting position?
I know from the docs that this is technically not possible (Utf8JsonReader is forward-only with no caching mechanism), but I want to know if I can achieve something equivalent in behaviour.
Below is my use case and the problem I have with…

Kjara
- 2,504
- 15
- 42
1
vote
2 answers
What is the best way to compare two objects in c#
I have two complex objects of the same type. I want to check if there is any difference between the two of these objects. I have two options of achieving this, either by converting both of these objects to string using JsonConvert.SerializeObject…

Rahul Kumar
- 11
- 1
- 2
1
vote
1 answer
Proper way to rethrow a JsonConverter exception
I have the following setup for deserializing some json:
parsedResponse = JsonConvert.DeserializeObject(
json,
new JsonSerializerSettings
{
Error = (object sender, ErrorEventArgs args) =>
{
throw new MyParseException($"Parse…

derekantrican
- 1,891
- 3
- 27
- 57