Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net - How to get / deserialize object of JsonPatchDocument?

I could serialize the JsonPatchDocument model by using JsonConvert.SerializeObject(), but the type of result is string, how can I convert it to normal array type? Or how to get JsonPatchDocument object straight to array?

var pathSerialized = JsonConvert.SerializeObject(patch);
Console.WriteLine(pathSerialized);

// Result as string: 
// "[{"value":"2018-08-30","path":"/openTo","op":"replace"},{"value":"2018-04-01","path":"/openFrom","op":"replace"}]" 
like image 921
Hoàng Nguyễn Avatar asked Sep 16 '25 13:09

Hoàng Nguyễn


1 Answers

You don't have to serialize the JsonPatchDocument object at all. You can access its properties directly through the object. For example filtering for the path property:

var elementsWithPath = patch.Operations.Where(o => o.path.Equals("some path"));
like image 84
croxy Avatar answered Sep 18 '25 10:09

croxy