-
Notifications
You must be signed in to change notification settings - Fork 0
JsonPathManager.Force(string path, object value) Method
Note: as of v0.3.0, this method is obsolete. Use JsonPathManager.Add(string path, object value, Priority priority) with Priority.High instead to achieve the same functionality.
Force a value to the JsonPathManager tree.
JsonPathManager.Force(string path, object value);JsonPathManager instance = new JsonPathManager();
instance.Force("$.path.to.location", "value");The path to the location where the value should be forced.
See JsonPathSerializer Supported Paths.
The value to force at the location specified by the path.
Both methods would add an object at the given path. However, JsonPathManager.Add throws exceptions at some cases where the operations might unintentionally override some existing values on the root, whereas JsonPathManager.Force is guaranteed to succeed.
For example:
-
Given root
{ "name" : "John" },JsonPathManager.Add("$.name.first", "John")throws an exception, butJsonPathManager.Force("$.name.first", "John")would yield{ "name" : { "first" : "John" } }; -
Given root
{ "name" : { "first" : "John" } },JsonPathManager.Add("$.name", "John")throws an exception, butJsonPathManager.Force("$.name", "John")would yield{ "name" : "John" }; -
Given root
{ "name" : { "first" : "John" } },JsonPathManager.Add("$.name[0]", "John")throws an exception, butJsonPathManager.Force("$.name[0]", "John")would yield{ "name" : [ "John" ] };
v0.1.2 and above
- v0.3.0
- v0.2.0
- v0.1.2