0

I want to read a json file, loop through "data" from json and mask the elements. Below is what I tried so far. Can someone please help me.

static void Main(string[] args)
{
    var options = new JsonSerializerOptions
    {
        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        WriteIndented = true
    };
    var jsonString = File.ReadAllText(@"C:\Students\StudentsData.json");

    JObject o = JObject.Parse(File.ReadAllText(@"C:\Students\StudentsData.json"));

    var results = from x in o["returnData"].Children()
                    //where x["Address1"].Value<string>() == "Address1"
                    select x;           
}
{
   "returnData":{
      "type":"ISet<MyStudents>",
      "name":null,
      "data":"[\n  {\n    \"StudentDetails\": {\n      \"Address1\": \"1234 First Street\",\n      \"Address2\": null,\n      \"Address3\": null,\n      \"Address4\": null,\n      \"City\": \"First Street\"  }\n]"
   }
}
J.F.
  • 11,073
  • 8
  • 23
  • 48
  • 1
    There is no problem here, just a statement of intent and a plea for assistance. Please read [ask] – TheGeneral Nov 13 '20 at 07:55
  • 1
    Data is not a `ISet`, it's a Json string representing a `ISet` Dezerialize the StudentsData.json. Get to the data Key. And deserialize it's value. – Drag and Drop Nov 13 '20 at 07:55
  • Related: [Json.Net deserialize JSON string inside a string](https://stackoverflow.com/questions/44132558/json-net-deserialize-json-string-inside-a-string) – Drag and Drop Nov 13 '20 at 07:57
  • I was able to get the deserialized string. But, looking for help on mask. For eg: I have 270. What can I use to get 193. Any idea. – jimanthony Nov 13 '20 at 23:25
  • Your question sounds like it might be a duplicate of [How to mask sensitive values in JSON for logging purposes](https://stackoverflow.com/q/37821298/10263), or at least very similar. Take a look and see if that answers your question. – Brian Rogers Nov 14 '20 at 01:15
  • Well, Partly that fulfills the requirement. Can I also know, how to apply design principles when reading a json file. – jimanthony Nov 16 '20 at 17:18

0 Answers0