title: Searching for fields in a Json file in C#
body: <p>I have a Json file with couple of fields and I have some problems searching for specific fields.</p>
  
  <p>This is the Json file(I cut it short since the original is huge):</p>
  
  <pre><code>{
    "errors": {
      "errorCode": 0,
      "errorMessage": "",
      "errorDescription": null
    },
    "pagination": {
      "recordsReturned": 250,
      "totalRecordsFound": 123,
      "currentPage": 1,
      "recordsPerPage": 250
    },
    "data": {
      "totalDCount": 1713,
      "totalValue": "50",
      "totalCarats": 60,
      "averagePricePerCarat": 21,
      "averageDiscount": -0.29,
      "dResult": [
        {
          "color": "H",
          "dID": 4693,
          "fancyColor": {
            "dominantColor": null,
            "secondaryColor": null,
            "overtones": null,
            "intensity": null,
            "color1": null,
            "color2": null
          },
          "seller": {
            "accountID": 124,
            "companyName": "",
            "companyCode": " ",
            "founded": "",
            "address": null,
            "telephone": " ",
            "fax": null,
            "email": null,
            "contactPrimaryName": "value",
            "city": null,
            "state": null,
            "country": "USA",
            "address1": null,
            "address2": null,
            "skypeName": null,
            "primarySupplierBadge": true,
            "ratingPercent": 1.0,
            "totalRating": 1.0,
            "relatedAccounts": null
          },
  
            "shape": "Round",
            {
          "color": "H",
          "dID": 46,
          "fancyColor": {
            "dominantColor": null,
            "secondaryColor": null,
            "overtones": null,
            "intensity": null,
            "color1": null,
            "color2": null
          },
          "seller": {
            "accountID": 124,
            "companyName": "",
            "companyCode": " ",
            "founded": "",
            "address": null,
            "telephone": " ",
            "fax": null,
            "email": null,
            "contactPrimaryName": "value",
            "city": null,
            "state": null,
            "country": "USA",
            "address1": null,
            "address2": null,
            "skypeName": null,
            "primarySupplierBadge": true,
            "ratingPercent": 1.0,
            "totalRating": 1.0,
            "relatedAccounts": null
          },
  
            "shape": "Round" 
  
        }
      ]
    }
  }
  </code></pre>
  
  <p>I wrote a code that should search for "dId" field value under the "dResult". Unfortunately this error comes up (I am using Newtonsoft.Json parser) :</p>
  
  <p>"Newtonsoft.Json.JsonReaderException: Invalid property identifier character: {. Path 'data.dResult[0].shape', line 54, position 11."</p>
  
  <p>A.This is the code I wrote, I would be happy if you could tell me what is the problem ?</p>
  
  <p>B.A second problem that I had is that I need to pick only the "dID" of those that have the "shape" field value as "Round", I didn't figure out a way to do that since I need to go and find a further field while encountering "dId" field .</p>
  
  <pre><code>  class Program
  {
      static void Main(string[] args)
      {
          string filepath = "../../json1.json";
          string result = string.Empty;
          string str = string.Empty;
          using (StreamReader r = new StreamReader(filepath))
          {
  
  
              var json = r.ReadToEnd();
  
  
              JObject jObject = JObject.Parse(json);
              JToken jUser = jObject["data"];
              string jsonString = jUser.ToString();
              JObject jObject1 = JObject.Parse(jsonString);
  
              JToken jUser2 = jObject1["dResult"];
  
              string jsonString2 = jUser2.ToString();
              JObject jObject2 = JObject.Parse(jsonString2);
  
  
              foreach (var item in jObject2.Properties())
                  {
  
                  if (item.Name == "dID")
                  {
                      str = item.Value.ToString();
  
                              result = result + " " + str;
                  }
  
          }
  
      }
  
          Console.WriteLine(result);
  
      }
  }
  </code></pre>
  
  <p>Reference for the comment I received here (Another Json section, this is under "dResult"):</p>
  
  <pre><code>, {
          "dID": 281242,
          "seller": {
              "accountID": 21321,
              "companyName": "RA",
              "companyCode": "001",
              "founded": "000",
              "address": null,
              "telephone": "999",
              "fax": null,
              "email": null,
              "contactPrimaryName": "name",
              "city": null,
              "state": null,
              "country": "USA",
              "address1": null,
              "address2": null,
              "skypeName": null,
              "primarySupplierBadge": true,
              "ratingPercent": 1.0,
              "totalRating": 1.0,
              "relatedAccounts": null
          },
          "shape": "Round",
          "size": 0.010,
          "color": "K",
          "fancyColor": {
              "dominantColor": null,
              "secondaryColor": null,
              "overtones": null,
              "intensity": null,
              "color1": null,
              "color2": null
          },
  </code></pre>