Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why are the JSON values emtpy

I got a very simple controller that reads json from a local file, parses it into a JObject with JObjects.parse, and then returns it with Ok().

The result shows the JSON, however the values are "empty"

The code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The result

The test JSON i’m using

{
    "version": "1.3",
    "status": "ok"
}

If I add a breakpoint, the response variable seems to be correctly filled:
Breakpoint

Does anyone have any clue what could be the issue here?

>Solution :

ASP.NET Core for several versions (since 3rd version if I remember correctly) now uses System.Text.Json as default serializer, which knows nothing about JObject from Newtonsoft one. You need to either switch to Newtonsoft Json (see here for example) – add Microsoft.AspNetCore.Mvc.NewtonsoftJson nuget and use AddNewtonsoftJson (for example services.AddControllers().AddNewtonsoftJson();)

Or use System.Text.Json capabilities for example JsonNode API (available since .NET 6).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading