The problem is, that `json_encode()` function in PHP leaves ambiguity for tools which are reading its output. In PHP both lists and dictionaries are same type of `array`.

```
echo json_encode([]); // []
echo json_encode(["5" => "something"]); // {"5": "something"}

```

In JSON.NET I want to force both `[]` and `{"5": "something"}` to convert to `Dictionary<string, string>` type. However it recognizes `[]` as prohibited structure for Dictionary and throws an Exception.

Can I quickly leave empty JSON arrays nulled or force them to convert to empty Dictionary type?

**FINAL SOLUTION**

I modified accepted answer to make it generic and reusable for other types.

```
public class DictionaryOrEmptyArrayConverter<T,F> : JsonConverter
{
    public override bool CanWrite { get { return false; } }
    public override bool CanConvert(Type objectType)
    {
        return objectType == typeof(Dictionary<T, F>);
    }
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        switch (reader.TokenType)
        {
            case JsonToken.StartArray:
                reader.Read();
                if (reader.TokenType == JsonToken.EndArray)
                    return new Dictionary<T, F>();
                else
                    throw new JsonSerializationException("Non-empty JSON array does not make a valid Dictionary!");
            case JsonToken.Null:
                return null;
            case JsonToken.StartObject:
                var tw = new System.IO.StringWriter();
                var writer = new JsonTextWriter(tw);
                writer.WriteStartObject();
                int initialDepth = reader.Depth;
                while (reader.Read() && reader.Depth > initialDepth)
                {
                    writer.WriteToken(reader);
                }
                writer.WriteEndObject();
                writer.Flush();
                return JsonConvert.DeserializeObject<Dictionary<T, F>>(tw.ToString());
            default:
                throw new JsonSerializationException("Unexpected token!");
        }
    }

    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        throw new NotImplementedException();
    }
}

```

You should use it with your JSON object as in example below:

```
public class Company
{
    public string industry_name { get; set; }

    [JsonConverter(typeof(DictionaryOrEmptyArrayConverter<int, Upgrade>))]
    public Dictionary<int, Upgrade> upgrades { get; set; }
}

public class Upgrade
{
    public int level { get; set; }
}

```

It allows you to quickly convert JSON string to objects with `DeserializeObject` method:

```
var result = JsonConvert.DeserializeObject<Company>(jsonString);

```