Share Link
Copied to clipboard
Embed on Your Page
Copied to clipboard
We Stand with Ukraine
https://stackoverflow.com/questions/76276372/json-deserialize-in-one-data-as-array-and-in-one-as-json-object-coming-tricky-no by dbc_MinLength
Environment version: .NET 9.0.0 (9.0.0), Unix 6.8.0.1014
Newtonsoft.Json version: Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed

Input JSON:
{
  "variants": [
    {
      "name": "test1",
      "description": "test1",
      "images": []
    },
    {
      "name": "test2",
      "description": "test2",
      "images": {
        "WHITE": [
          {
            "id": "ttest",
            "product_id": "ttest"
          }
        ]
      }
    }
  ]
}
Images for test1:
Images for test2:
  For color WHITE:
    id = ttest
Re-serialized TestClass:
{
  "variants": [
    {
      "name": "test1",
      "description": "test1",
      "images": {}
    },
    {
      "name": "test2",
      "description": "test2",
      "images": {
        "WHITE": [
          {
            "id": "ttest",
            "product_id": "ttest"
          }
        ]
      }
    }
  ]
}
Cached Result
Last Run: 10:12:01 pm
Compile: 0.021s
Execute: 0.18s
Memory: 16.61Mb
CPU: 0.201s