Class JsonExtensions
public static class JsonExtensions
- Inheritance
-
JsonExtensions
- Inherited Members
Methods
AddJsonProperty<TPropertyType>(string, string, TPropertyType)
Adds a new property with the specified name and value to the given JSON string.
public static string AddJsonProperty<TPropertyType>(this string jsonText, string propertyName, TPropertyType propertyValue)
Parameters
jsonText
stringThe original JSON string.
propertyName
stringThe name of the property to add.
propertyValue
TPropertyTypeThe value of the property to add.
Returns
- string
A new JSON string with the added property.
Type Parameters
TPropertyType
The type of the property value to add. If it is string in JSON format, it is added as another JSON node.
CombineWithJson(string, string)
Merges two JSON objects represented as strings.
The otherJson
object will overwrite existing properties in baseJson
or add new ones.
public static string CombineWithJson(this string baseJson, string otherJson)
Parameters
baseJson
stringThe original JSON string to be merged into.
otherJson
stringThe JSON string containing properties to merge into
baseJson
.
Returns
- string
A new JSON string representing the merged result of
baseJson
andotherJson
.
RemoveJsonProperty(string, string)
Removes a property with the specified name from the given JSON string.
public static string RemoveJsonProperty(this string jsonText, string propertyName)
Parameters
Returns
- string
A new JSON string without the specified property.
ToExpando(string)
Parses given text (in JSON structure) to case-insensitive expando object (CaseInsensitiveExpandoObject).
public static CaseInsensitiveExpandoObject ToExpando(this string jsonText)
Parameters
jsonText
stringText to be parsed into case-insensitive expando object (CaseInsensitiveExpandoObject).
Returns
- CaseInsensitiveExpandoObject
CaseInsensitiveExpandoObject representation of JSON stored in
jsonText
.
ToJson(string)
Parses given text to Newtonsoft.Json.Linq.JObject form.
public static JObject ToJson(this string text)
Parameters
text
stringText to be parsed into Newtonsoft.Json.Linq.JObject.
Returns
- JObject
Newtonsoft.Json.Linq.JObject representation of JSON within
text
.
ToJsonString(object)
Serializes object to string in JSON structure.
public static string ToJsonString(this object obj)
Parameters
Returns
To<TResult>(string)
Convert JSON string to TResult
.
public static TResult? To<TResult>(this string jsonText)
Parameters
jsonText
stringString in JSON structure, object should be extracted from.
Returns
- TResult
jsonText
in aTResult
form.
Type Parameters
TResult
Type which JSON string will be deserialized to.