ay89 ay89 - 1 year ago 97
JSON Question

how to update a particular value in json?

I am using newtonsoft json library. I want to update value of a token "Status" from false to true in following json. How can I do that?:

"type": "FeatureCollection",
"Status": false,
"crs": {
"type": "EPSG",
"properties": {
"code": 28992

Answer Source

You can deserialize it, modify the value and serialize it again

dynamic jsonObject = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString);
jsonObject.Status = true;
var modifiedJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObject);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download