Questions tagged [json.net]
Json.NET (also known as Newtonsoft.Json) is a popular high-performance JSON framework for .NET.
12,898
questions
1
vote
3
answers
38
views
How do you parse an array of objects with Newtonsoft?
I just want to get this JSON into some kind of an object. JArray and JToken are completely confusing to me.
I can create a class so that Newtonsoft knows what to map to but if you will notice the ...
0
votes
0
answers
38
views
How to fix The return type of an async method must be void, Task or Task<T> [closed]
I've written the below code for making Http Requests(Get and Post) :
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using ...
-1
votes
0
answers
17
views
What is the best way to remove HTML tags from a Newtonsoft JObject
Is there a decent way of removing simple html tags from inside a JObject? I don't want to try to do things like convert it to a string and then try to rip the html out... Those approaches tend to ...
0
votes
0
answers
18
views
Setting json serializer settings in startup netcoreapp 3.1
Hey all how do i correctly update my json SerializerSettings in my netcoreapp 3.1 application? Im trying to update this setting in the startup.cs I've tried to set this two ways, by using ...
1
vote
1
answer
40
views
Deserialize class with an array of base objects into class with an array of inherited objects (Newtonsoft.Json)
I've been working on a music game and decided to add convertation of other games' levels. One of the games I decided to convert from uses JSON to store it's levels and so I'm using Newtonsoft.Json for ...
0
votes
1
answer
62
views
How to rename key value pair within a nested json structure in C#
Hello everyone and thanks for helping me in advance. The following question might sound silly but I'm a beginner about it.
Let's start!
I have the following json that comes from a web api.
{
"...
0
votes
1
answer
60
views
.NET JsonDeserializer fails when I rename List<> property with JsonProperty
I'm trying to deserialize json that looks like this:
{
"Total": 1,
"Page": 1,
"Products": [
{
"ID": "524c20a3-a8ec-44f2-9685-311f1f7d1498&...
0
votes
0
answers
49
views
c#/json.net deserialize child with data from parent
class Item
{
public string Id;
public List<Item> Children;
}
json
{
"Id" : "/parent",
"Children" : [
{
&...
1
vote
1
answer
58
views
How to change a key value pair within a nested json structure C#
Hello everyone and thanks for helping me in advance.
The following question might sound silly but I'm a beginner about it.
I have the following json which comes from a web api:
{
"status"...
0
votes
1
answer
40
views
ASP.Net core - blank response when returning a JObject property
I am using ASP.Net core 5.0 and want to return IEnumerable of an object as Action method response.
Here is the response class:
public class TestResponse
{
public int Id { get; set; }
public ...
1
vote
1
answer
42
views
.NET Newtonsoft Allow property to be only serialised
I have implemented the answer from this (rather old) question https://stackoverflow.com/a/31732029/4180176 but it doesn't seem to work for me and I can't figure out why.
I can indeed see that property....
4
votes
1
answer
57
views
C# reflection - get object value from property value within JSON ContractResolver
I have a class PersonDto which contains a property instance of type AddressDto. I am building a custom ContractResolver named eg. ShouldSerializeContractResolver with Newtonsoft.Json marshalling .NET ...
-2
votes
0
answers
27
views
C# Get part of JSON stream using JsonPath
I have JSON stream with content
[
{
"boolVar": true,
"childArray": [
{
"name": "Annie",
"age": 18
...
0
votes
1
answer
27
views
Iterate a JSON data, put comma after each run and SerializeObject
I am trying to iterate (Do While) JSON data input, put Comma after each run, and put [ ] around at the end.
var query = new QueryFunction()
{
Offset = 0,
PageSize = 2
};
do
{
query....
-1
votes
0
answers
28
views
C# how to serialize property of type class Newtonsoft [duplicate]
public class Driver : BaseEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName => $"{FirstName} {LastName}&...
1
vote
1
answer
59
views
GitHub actions deploys wrong version of Newtonsoft.Json nuget package to Azure
I have a GitHub action doing .net solution build, test and deploy to Azure:
name: Build and deploy ASP.Net Core app to Azure Web App - project-test-api
on:
push:
branches:
- main
...
1
vote
1
answer
19
views
Jtoken containing DateTime tostring unexpected behaviour
I have this json:
{
"sku": "articlenumber",
"lastModified": "2022-05-06T10:07:23.934Z",
"quantity": 20
}
I have to send the exact value of &...
-2
votes
2
answers
33
views
Deserialization of the string path to the file with Newtonsoft [closed]
[enter image description here][1]I am trying to deserialize a string representation of a file path and get an error "Bad JSON escape sequence: \h."
Screenshot of the error
1
vote
1
answer
82
views
Unable to load one or more of the requested types. Could not load file or assembly 'Newtonsoft.Json, Version=10x, Culture=neutral, PublicKeyToken=xxx
I have an error when I deploy my asp.net app to azure. I got 500.30 error response when the deployment was successful, I check the logs file and it said
System.Reflection.ReflectionTypeLoadException: ...
0
votes
1
answer
31
views
Newtonsoft Unexpected character while parsing value
I have the problem that I always get this error when deserializing an object. But when I use the bracketed code it works, but not when I retrieve it from my api
Unexpected character encountered while ...
2
votes
2
answers
51
views
How can I force an exception to be thrown when deserializing a dictionary with duplicated keys from JSON?
I have a data model with a Dictionary<string, string> of attributes as follows:
public class Model
{
public string Name { get; set; }
public Dictionary<string, string> Attributes { ...
0
votes
1
answer
49
views
How to use "oneOf" in this schema?
I'd like to have either A or B, but not both (mutual exclusive.)
I have to use whatever is avaliable in Draft 3, even though it says 4 on the top. Reason being, when using array for "required&...
0
votes
1
answer
46
views
HTTP Post request method does not execute. How to use HttpClient?
I'm trying to make a post request using HttpClient. The expected json which I'm trying to post is stored in var result and looks like :
{
"ID": 142,
"StationNo": 19,
"...
0
votes
0
answers
26
views
Is it possible to use EF 6, and Newtonsoft.Json at the same time?
I am using EF6 to manage multiple DataContexts (3 different and distinct data connections). In one DbContext, the view that I have been granted access to has a field that contains serialized Json ...
-1
votes
2
answers
111
views
How to Deserialize complex JSON and create it as C# Object
I have a JSON which looks like as follows :
{
"Values": [
{
"MsgSource": null,
"TagName": "Data.New_MSG",
"...
0
votes
1
answer
39
views
Xamarin Forms Array in Listview
i recently created a question on stackoverflow but updated the whole question, so i thought it would be better to create a new question.
When i want to create a ticket the array is not parsed, how do ...
0
votes
0
answers
37
views
Newtonsoft get value from hierarchical JSON using single dynamic selector [duplicate]
I'm looking for a way to pass a single string selector to get a value from hierarchical JSON. This selector could be id, location.name, or even deeper, it has to be dynamic.
I have this JSON:
{
"...
1
vote
1
answer
38
views
Which schema draft does Newtonsoft 12 use?
I am working on a remote PC that only has Newtonsoft.Json.dll 12.0.3.23909 and PowerShell 5.
I cannot install new software or transfer files as this tool will be used on other PCs and I can't ship ...
0
votes
1
answer
18
views
ASP.NET convert part of JSON file to JArray
I have this JSON that I'm trying to parse with Newtonsoft and convert to an array:
{
"generatedAt": "2022-01-01 02:03:25",
"myitems": [
{
"id": "...
0
votes
0
answers
42
views
Continually call an API till data are available
An api can give me two types of response in json.
Response 1:
{
"status": "In Progress",
"message": "Dataset is not ready yet, try again in XXs"
}
Response ...
0
votes
1
answer
30
views
After json deserialization my object is still nothing although the json-string is correct
I already made a similar post about this topic, i applied all the changes they told me and tried their approaches, but it still didnt work (link: Object is nothing after json deserialization)
I want ...
-1
votes
0
answers
29
views
Can't deserialize json because api returns numbers instead of names
I need to Deserialize Json that I get from Bitrue API using Json.DeserializeObject() method. How my class should look like if I get this (Look at the picture). I mean that I get values but there are [...
-2
votes
1
answer
43
views
How to delete a property in a JArray?
I have a JArray as below, the file property contained a base64 string so it's a big size, how to delete it?
{
"files": [
{
"filename": "...
0
votes
2
answers
55
views
JArray Strings to JArray of Objects
I am trying to add a JArray towards a Jobject that is created manually and using that JObject to do a Put API Call.
The JArray I get is the below:
[
"{\"name\":\"route4\",\&...
-1
votes
0
answers
31
views
How to convert Api Response using jsonapidotnetcore package Asp.net core
I am working on application I need to use jsonapidotnetcore nuget package to convert my json api response. Here is my implementation
public async Task<List<UrlDTO>> GetUrlList()
{
...
-1
votes
1
answer
127
views
Could not load Newtonsoft.Json. Issue with .net framework / core / standard versions
[EDIT 3: bottom line, this stuff can work but is fragile. take a false step and VS will pull in undesired versions. Be prepared to backup, undo changes, and try again.]
[EDIT 2: I was able to go from ...
0
votes
0
answers
26
views
Adding Newtonsoft JsonProperty tags to Entity Framework models (asp.net core)
Entity Framework database first add Newton soft JsonProperty Attribute. Have done a search and am probably not getting the concept, so as a stop gap have used the following regex in order in note pad++...
2
votes
0
answers
74
views
Newtonsoft.Json: Very Slow Serialization on Azure
I've stumbled upon a really strange problem. I'm trying to Serialize using Newtonsoft a quite large object. In my local machine I have tried to measure the time needed to do that and it's around 500-...
-1
votes
0
answers
25
views
How can I read a value from a nested JSON file? [duplicate]
I have the following JSON file, and I need to get the very first definition of the word. But it is nested quite deep and I'm not sure how to do it?
What I need:
"definition": "A ...
0
votes
1
answer
21
views
How can I upgrade newtonsoft in outsystems 10
I'm trying to upgrade outsystems eSpaces from version 9 to 10 and I'm facing this error:
Internal Error
Compilation Error.
bin\OutSystems.RESTService.Runtime.dll: error CS1705: Assembly 'OutSystems....
0
votes
1
answer
39
views
Transforming JSON template based on JSON values posted into API
I have got a requirement of building an azure function which transforms data in our COSMOS DB based on the value posted by a calling service.
So consider this JSON template
{
"...
-1
votes
1
answer
48
views
Parse (Deserialize) JSON with dynamic keys (C#)
I want to parse the JSON on the bottom. Till now I always have the static key for the variables, but in this example, the keys are always changing. Here the "58e7a898dae4c" and "...
1
vote
2
answers
78
views
Flatten nested JSON with JSON.NET in C#
I receive a bill of materials in JSON format via a WebApi, which has a corresponding hierarchy.
The hierarchy or the nesting can be any depth.
An example bill of materials is shown below:
{
"...
0
votes
0
answers
25
views
HTML Encoding a JSON Request body before binding to model in dotnet5 (dotnet core)
The requirement was to ensure that we HTML encode any of the deserialized properties to prevent an API client from sending in HTML and script tags which would then be stored in the database.
For ...
1
vote
0
answers
21
views
C# saving any JSON string as a Firestore document
I'm trying to retrieve a document from Firestore, edit it as a plain-text JSON, and then reupload the changes. I'm using JSON.net to deserialize the string to Dictionary<string, object>, and ...
-1
votes
0
answers
25
views
I have json file (it is the source) with me, and we are taking data from json and i need to populate in tables which i have
I have json file (it is the source) with me, and we are taking data from json and i need to populate in tables which i have ..
I have list of 10 tables in excell.
Can any one please help me
0
votes
2
answers
32
views
IgnoreNullValue not working when serializing an Anonymous Object
The Problem
I am creating an anonymous object in a method and assigning it properties from a class. Some of the properties can sometimes be empty (strings) and I eventually need to serialize the ...
0
votes
0
answers
84
views
Custom Endpoint Json Serialization in ASP.NET Core
Is it possible to specify unique JSON serialization settings on an individual ASP.NET Core API endpoint, that differs from the default settings one has set at the project (default) level?
So for ...
0
votes
1
answer
66
views
Using Newtonsoft JsonConverter to Encrypt JSON object
I'm developing a project that will require me to include credentials for things like an SMTP server. I'd like to store this information along with the complete details of the endpoint in an embedded ...
0
votes
1
answer
49
views
Deserialize a list of lists
I'm afraid this may be a long one. I have a list of records. Each record has record details. I get back json that looks like this
d": {
"__type": "xVehicleAlarm....