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
2 answers
How to SerializeObject which contains string value stored in BinaryData?
I am trying to Serialize ServiceBusReceivedMessage where the Message body is declared as BinaryData. So when I try to execute the below code, the body of the message is returned empty whereas the remaining properties in ServiceBusReceivedMessage are…

HobbyLobbyVS
- 61
- 1
- 10
2
votes
1 answer
Deserializing a class with a generic type parameter using JsonConvert in C#
I have a somewhat complex class hierarchy which I am attempting to deserialize using JsonConvert.
This is an extremely contrived example of what I'm trying to do. Note that:
I am not able to modify the Deserializable class, and I must inherit from…

lyneca
- 31
- 1
- 3
2
votes
1 answer
How do I serialize (NewtonSoft) a class that includes an interface with a property named Type?
I need to serialize a result of this class (Assembly Adyen, Version=6.0.0.0):
Public Class PaymentResponse
Implements IEquatable(Of PaymentResponse), IValidatableObject
Public Sub New(...)
…

Bjarke
- 23
- 4
2
votes
1 answer
Why does assigning a JArray to a var fail when I call JsonConvert.DeserializeObject()?
On this line of code:
var arr = JsonConvert.DeserializeObject(s);
...I am getting, "Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray'."
I changed that line to this:
JArray arr =…

B. Clay Shannon-B. Crow Raven
- 8,547
- 144
- 472
- 862
2
votes
1 answer
Newtonsoft Json reference loop converter with derived class
Usually, for derived types deserialization, you have to define a custom converter. I mean when there is a base class - Base and others derived from the Base. For that case you have to define a custom convevrter and use some data (maybe an enum) from…

Gabriel Anton
- 444
- 1
- 6
- 14
2
votes
1 answer
JsonConvert unable to serialize correctly with brackets
I'm trying to post two fields and a bundled object with two fields to Mailchimp's API endpoint.
var store_id = ConfigurationManager.AppSettings["MailChimpStoreID"];
var method = String.Format("ecommerce/stores/{0}/products?",…

kzone95
- 49
- 6
2
votes
1 answer
How to make JsonConvert.DeserializeObject() parse array when I won't always be passing array to it?
I have a method in my ASP.Net app that looks like this:
Method1(String inputString)
{
return JsonConvert.DeserializeObject(inputString);
}
I pass stringified objects to Method1, and one of them is a stringified version of this object:
obj1:…

gkeenley
- 6,088
- 8
- 54
- 129
2
votes
1 answer
JsonConvert.PopulateObject not working with boolean value
The below code wont map false over a true property using JsonConvert.PopulateObject. The other properties work just fine. Am I doing something wrong?
JsonConvert.PopulateObject(json, request);
JSON
{ "EventId": 146282, "Name": "api division 9",…

Mike Flynn
- 22,342
- 54
- 182
- 341
2
votes
2 answers
JsonConvert not initialising properties when deserializing unless setter is generic
Why is JsonConvert not able to initialise property values when getter/setter are not the generic/default ones.
For instance, JsonConvert will deserialise the following class (or rather Property "Value") as it should. Say my Json file contains Value…

stackMeUp
- 522
- 4
- 16
2
votes
1 answer
How to read JSON sub object as a string
Example:
{ "Header": { "Test": "Value" } }
I would like to retrieve the Header's value as a String, but not as an object.
Means the value of Header, { "Test": "Value" } is retrieved as a string.
This is part of a very large response, the above…

s k
- 4,342
- 3
- 42
- 61
2
votes
1 answer
How to serialize json in order to display property value instead of property name?
I am trying to find a way to serialize object to json string in the following format, so I can meet project requirements
{
"id": 123456,
"los": {
"2019-05-13": [
{
"currency": "EUR",
"guests": 2,
"price": [
…

mko
- 6,638
- 12
- 67
- 118
2
votes
1 answer
DeSerialize JSON with variable having a $ sign
This is my incoming JSON packet:
{
"schema":{
"rid":0,
"$esn":"eventhub1",
"properties":[
{
"name":"deviceId",
"type":"String"
},
{
"name":"product",
…

MAK
- 1,250
- 21
- 50
2
votes
1 answer
Why does an F# Discriminated Union fails to have its TypeConverter respected by JSON.NET but other types can?
#r "../packages/Newtonsoft.Json.12.0.3/lib/netstandard2.0/Newtonsoft.Json.dll"
type [)>] C = A of string
and CC() =
inherit System.ComponentModel.TypeConverter()
override…

Happypig375
- 1,022
- 1
- 12
- 32
2
votes
1 answer
Saving and Loading Dictionary from File
I'm trying to save a dictionary to a file and load the contents of the same to a Dictionary Object.I'm appending the dictionary to a file using the following code
string json = JsonConvert.SerializeObject(dict);
File.AppendAllText("config.fcj",…

techno
- 6,100
- 16
- 86
- 192
2
votes
2 answers
Handle undefined values while deserializing object using JsonConvert in c#
I have a Json serialized configuration in which I need to deserialize the object using
JsonConvert.DeserializeObject<>(jsonConfig)
to Myclass list.
In jsonConfig there may be some properties missing where I got an exception like below.
Required…

Yuvaranjani
- 300
- 2
- 12