# question

## JsonSerializer.Deserialize JsonSerializerOptions

I have a Model can appears both as an Object and/or Array in data I am trying to deserialize. Is there an option that forces the deserializer to consume an Object as a single record Array?

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

There is no formal way to assert if json string is a single object of array.

If you were using Json.NET yes

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;

namespace IsJsonType
{
class Program
{
static void Main(string[] args)
{
Test1();
Test2();
}

private static void Test1()
{
var json = @"[{""Name"": ""11"",""RootPath"": ""\\\\somepath\\HTTP\\abc""},{""Name"": ""22"",""RootPath"": ""\\\\somepath\\HTTP\\def""}]";
var token = JToken.Parse(json);

if (token is JArray)
{
Console.WriteLine("array");
}
else if (token is JObject)
{
Console.WriteLine("single object");
}

}
private static void Test2()
{
var json = @"{""Name"": ""aaa"",""RootPath"": ""\\\\dddd\\HTTP\\qqqq""}";
var token = JToken.Parse(json);

if (token is JArray)
{
Console.WriteLine("array");
}
else if (token is JObject)
{
Console.WriteLine("single object");
}

}

}
}


Or this library yes

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LightWeightJsonParser;

namespace IsJsonType
{

class Program
{
static void Main(string[] args)
{
Test1();
Test2();
}

private static void Test1()
{
var json = @"[{""Name"": ""11"",""RootPath"": ""\\\\somepath\\HTTP\\abc""},{""Name"": ""22"",""RootPath"": ""\\\\somepath\\HTTP\\def""  }]";
var jsonObject = LWJson.Parse(json);
Console.WriteLine(jsonObject.IsArray);

}
private static void Test2()
{
var json = @"{""Name"": ""aaa"",""RootPath"": ""\\\\dddd\\HTTP\\qqqq""}";
var jsonObject = LWJson.Parse(json);
Console.WriteLine(jsonObject.IsArray);

}

}
}


· 3

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your reply. I don't know Json.Net as well as say XPATH.

How do I target a section of a JSON response to see if I end up with [ {} {} {} ] or just {}.

I also had the idea of going to a XML node, then its parent and then counting the number of the original node(s) and add an attribute that Newtonsoft uses to declare a node is of the array type. But that is proving difficult as well.

ScottRider-1472

Also, I was thinking that ItemConverterType = typeof(List<Model>) for Newtonsoft visually looks it is a declaration in their decorator but that was also wrong.