REST API returns "bad array" instead of JSON object REST API returns "bad array" instead of JSON object json json

REST API returns "bad array" instead of JSON object


I met also this issue recently. So, I've fixed it by adding this script in the Startup.cs file and ConfigureServices method :

services.AddMvc().AddJsonOptions(            options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore        );

So, you suffix services.AddMvc() by this code who means that you have to make JSON.Net to ignore cycles finded to the nested object request. And of course having Newtonsoft.Json package installed to your project and referenced in each concerned file

For much clearer information, see this link at Related Data and Serialization section :https://docs.microsoft.com/en-us/ef/core/querying/related-data

Hope this is helpfull for you