Table of Contents

Class JsonExtensions

Namespace
TeaPie.Json
Assembly
TeaPie.dll
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 string

The original JSON string.

propertyName string

The name of the property to add.

propertyValue TPropertyType

The 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 string

The original JSON string to be merged into.

otherJson string

The JSON string containing properties to merge into baseJson.

Returns

string

A new JSON string representing the merged result of baseJson and otherJson.

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

jsonText string

The original JSON string.

propertyName string

The name of the property to remove.

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 string

Text 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 string

Text 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

obj object

Object that should be serialized to JSON structured string.

Returns

string

string which represents obj in JSON structure.

To<TResult>(string)

Convert JSON string to TResult.

public static TResult? To<TResult>(this string jsonText)

Parameters

jsonText string

String in JSON structure, object should be extracted from.

Returns

TResult

jsonText in a TResult form.

Type Parameters

TResult

Type which JSON string will be deserialized to.