Read and Update data in Unknown Json Structure in c#

  • Thread starter Thread starter kapil kumar velpuri
  • Start date Start date
K

kapil kumar velpuri

Guest
Hi ,

I am building common component which used to read and update unknown json structure .

Example:

1 . docs.fullname in Example1.Json

2. Bill. in Example2.json

3. Borrowers. PersonalInfo.FirstName in Example3.json

4 PolicyInfo. BorrowerName in Example4.json

The every json file has different structure but I need to find the above json path in any where in the json file which need to read and update the value

My logic here

JObject jObj = JObject.Parse(jsonData);


//Reading parent node


JToken node = jObj.Descendants()

.Where(t => t.Type == JTokenType.Property && ((JProperty)t).Name == parentnode(docs, Bill,Borrower,Policyinfo))

.Select(p => ((JProperty)p).Value)

.FirstOrDefault()

//Reading child node value

//Reading data

foreach (JToken tempToken in node.Children())

{

string nodevalue = (string)tempToken.SelectToken(fullname or BorrowerFName or Borrowers );

}


//updating data

foreach (JToken tempToken in node.Children())
{


tempToken.SelectToken(fullname or BorrowerFName or Borrowers).Replace(new value)

}

Please share if any other good approaches .

Continue reading...
 
Back
Top