json.net

F#: How to apply Json.NET [JsonConstructor] attribute to primary constructor?

不羁的心 提交于 2021-02-07 14:36:47
问题 I'm trying to do something in F# like the JsonConstructorAttribute example in the Json.NET documentation: public class User { public string UserName { get; private set; } public bool Enabled { get; private set; } public User() { } [JsonConstructor] public User(string userName, bool enabled) { UserName = userName; Enabled = enabled; } } The analog in F# appears to be something like the following, but I'm getting an error on the placement of [<JsonConstructor>] : [<JsonConstructor>] // ERROR!

F#: How to apply Json.NET [JsonConstructor] attribute to primary constructor?

余生长醉 提交于 2021-02-07 14:34:31
问题 I'm trying to do something in F# like the JsonConstructorAttribute example in the Json.NET documentation: public class User { public string UserName { get; private set; } public bool Enabled { get; private set; } public User() { } [JsonConstructor] public User(string userName, bool enabled) { UserName = userName; Enabled = enabled; } } The analog in F# appears to be something like the following, but I'm getting an error on the placement of [<JsonConstructor>] : [<JsonConstructor>] // ERROR!

PowerShell — Accessing a JArray inside a JObject

ε祈祈猫儿з 提交于 2021-02-07 14:24:20
问题 I have a Json object { "ProjectDirectory": "C:\\Main", "SiteName": "RemoteOrder", "ParentPath": "/Areas//Views", "VirtualDirectories": [ { "Name": "Alerts", "Path": "\\Areas\\RemoteOrder\\Views\\Alerts" }, { "Name": "Analytics", "Path": "\\Areas\\RemoteOrder\\Views\\Analytics" }, { "Name": "Auth", "Path": "\\Areas\\RemoteOrder\\Views\\Auth" } ] } that I created by $config = [Newtonsoft.Json.Linq.JObject]::Parse($file) I can access things like $config["ProjectDirectory"] $config[

JSON Objects are serialized to empty brackets when returned using JsonResult

瘦欲@ 提交于 2021-02-07 10:20:20
问题 I am operating in the .NET Framework using ASP.NET MVC 5. I have an MVC Controller that is using Newtonsoft.Json (or json.net) to build a nice JSON object. The trouble I'm running into is that when I return my json using the JsonResult method Json(JSONdotnetObject) , I end up with a result that has the same structure as what I would expect but everything is empty JArrays like so: Expected: { "prop": { ... some stuff ... }, "another prop": { ... more stuff ... } } Actual: [ [ ... empty ... ],

How do I concatenate two Json Objects using Json.Net (newtonsoft) [duplicate]

我们两清 提交于 2021-02-07 10:19:41
问题 This question already has answers here : Merge two Json.NET arrays by concatenating contained elements (3 answers) Closed 5 years ago . I have JSON objects that I want to concatenate into one JSON object. How do I do that using NewtonSoft's JSON package? 回答1: Use JContainer.Merge() . The logic for combining JSON objects together is fairly simple: name/values are copied across, skipping nulls if the existing property already has a value. Json.NET 6.0 Release 4 Example: var jObject1 = // Your

JSON Objects are serialized to empty brackets when returned using JsonResult

↘锁芯ラ 提交于 2021-02-07 10:19:20
问题 I am operating in the .NET Framework using ASP.NET MVC 5. I have an MVC Controller that is using Newtonsoft.Json (or json.net) to build a nice JSON object. The trouble I'm running into is that when I return my json using the JsonResult method Json(JSONdotnetObject) , I end up with a result that has the same structure as what I would expect but everything is empty JArrays like so: Expected: { "prop": { ... some stuff ... }, "another prop": { ... more stuff ... } } Actual: [ [ ... empty ... ],

How do I concatenate two Json Objects using Json.Net (newtonsoft) [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 10:18:14
问题 This question already has answers here : Merge two Json.NET arrays by concatenating contained elements (3 answers) Closed 5 years ago . I have JSON objects that I want to concatenate into one JSON object. How do I do that using NewtonSoft's JSON package? 回答1: Use JContainer.Merge() . The logic for combining JSON objects together is fairly simple: name/values are copied across, skipping nulls if the existing property already has a value. Json.NET 6.0 Release 4 Example: var jObject1 = // Your

Newtonsoft JSON.NET Security Vulnerability Implementation

落花浮王杯 提交于 2021-02-06 10:13:32
问题 The recently exposed security vulnerabilities regarding serialization in .NET have ambiguous recommendations. What is the correct way to securely use JSON.NET? Detailed guidance for JSON.NET: https://www.blackhat.com/docs/us-17/thursday/us-17-Munoz-Friday-The-13th-JSON-Attacks-wp.pdf#page=5 Should TypeNameHandling.All be used or should TypeNameHandling.None be used? General Explanation: https://www.bleepingcomputer.com/news/security/severe-deserialization-issues-also-affect-net-not-just-java/

Deserialize JSON to 2 different models

喜夏-厌秋 提交于 2021-02-06 09:38:08
问题 Does Newtonsoft.JSON library have a simple way I can automatically deserialize JSON into 2 different Models/classes? For example I get the JSON: [{ "guardian_id": "1453", "guardian_name": "Foo Bar", "patient_id": "938", "patient_name": "Foo Bar", }] And I need de-serialize this to the following models: class Guardian { [JsonProperty(PropertyName = "guardian_id")] public int ID { get; set; } [JsonProperty(PropertyName = "guardian_name")] public int Name { get; set; } } class Patient {

Optionally serialize a property based on its runtime value

◇◆丶佛笑我妖孽 提交于 2021-02-06 01:49:54
问题 Fundamentally, I want to include or omit a property from the generated Json based on its value at the time of serialization. More-specifically, I have a type that knows if a value has been assigned to it and I only want to serialize properties of that type if there has been something assigned to it (so I need to inspect the value at runtime). I'm trying to make it easy for my API to detect the difference between "has the default value" and "wasn't specified at all". A custom JsonConverter