Table of Contents

Class JsonUtil

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll
public static class JsonUtil
Inheritance
JsonUtil
Inherited Members

Properties

DefaultLoadSettings

public static JsonLoadSettings DefaultLoadSettings { get; }

Property Value

JsonLoadSettings

DefaultTextJsonSerializerOptions

public static JsonSerializerOptions DefaultTextJsonSerializerOptions { get; }

Property Value

JsonSerializerOptions

Methods

CreateSerializerForDomain(string, JsonSerializerSettings?)

public static JsonSerializer CreateSerializerForDomain(string domain, JsonSerializerSettings? settings = null)

Parameters

domain string
settings JsonSerializerSettings

Returns

JsonSerializer

DeserializeFastFromFile<T>(string, JsonSerializerOptions?)

Deserializes a file using System.Text.Json. Which means you need to make sure your objects do have the proper fields marked with System.Text.Json annotations to include and exclude them. The defaults for what to include and exclude are different from Newtonsoft.Json.

public static T? DeserializeFastFromFile<T>(string path, JsonSerializerOptions? settings = null)

Parameters

path string

Filepath

settings JsonSerializerOptions

If this is not specified, we set IncludeFields=true, WriteIndented=true and use Encoder=JavaScriptEncoder.Create(UnicodeRanges.All)

Returns

T

Type Parameters

T

DeserializeFast<T>(string, JsonSerializerOptions?)

Deserializes a string using System.Text.Json. Which means you need to make sure your objects do have the proper fields marked with System.Text.Json annotation to include and exclude them. The defaults for what to include and exclude are different from Newtonsoft.Json.

public static T? DeserializeFast<T>(string json, JsonSerializerOptions? settings = null)

Parameters

json string
settings JsonSerializerOptions

If this is not specified, we set IncludeFields=true, WriteIndented=true and use Encoder=JavaScriptEncoder.Create(UnicodeRanges.All)

Returns

T

Type Parameters

T

FromBytes<T>(byte[])

Reads a Json object, and converts it to the designated type.

public static T? FromBytes<T>(byte[] data)

Parameters

data byte[]

The json object.

Returns

T

Type Parameters

T

The designated type

FromString<T>(string)

public static T? FromString<T>(string data)

Parameters

data string

Returns

T

Type Parameters

T

PopulateObject(object, JToken, JsonSerializer)

public static void PopulateObject(object toPopulate, JToken token, JsonSerializer js)

Parameters

toPopulate object
token JToken
js JsonSerializer

PopulateObject(object, string, string, JsonSerializerSettings?)

public static void PopulateObject(object toPopulate, string text, string domain, JsonSerializerSettings? settings = null)

Parameters

toPopulate object
text string
domain string
settings JsonSerializerSettings

Populate<T>(JToken, T)

public static void Populate<T>(this JToken value, T target) where T : class

Parameters

value JToken
target T

Type Parameters

T

SerializeFastToFile<T>(string, T, JsonSerializerOptions?)

Serializes an object to a file using System.Text.Json. Which means you need to make sure your objects do have the proper fields marked with System.Text.Json annotations to include and exclude them. The defaults for what to include and exclude are different from Newtonsoft.Json.

public static void SerializeFastToFile<T>(string path, T data, JsonSerializerOptions? settings = null)

Parameters

path string

Filepath

data T
settings JsonSerializerOptions

If this is not specified, we set IncludeFields=true, WriteIndented=true and use Encoder=JavaScriptEncoder.Create(UnicodeRanges.All)

Type Parameters

T

SerializeFast<T>(T, JsonSerializerOptions?)

Serializes an object to a string using System.Text.Json. Which means you need to make sure your objects do have the proper fields marked with System.Text.Json annotation to include and exclude them. The defaults for what to include and exclude are different from Newtonsoft.Json.

public static string SerializeFast<T>(T data, JsonSerializerOptions? settings = null)

Parameters

data T
settings JsonSerializerOptions

If this is not specified, we set IncludeFields=true, WriteIndented=true and use Encoder=JavaScriptEncoder.Create(UnicodeRanges.All)

Returns

string

Type Parameters

T

ToBytes<T>(T)

Converts the object to json.

public static byte[] ToBytes<T>(T obj)

Parameters

obj T

The object to convert

Returns

byte[]

Type Parameters

T

The type to convert

ToObject<T>(JToken, string, JsonSerializerSettings?)

Converts a Json token to a typed object.

public static T? ToObject<T>(this JToken token, string domain, JsonSerializerSettings? settings = null)

Parameters

token JToken

The token to deserialize

domain string

The domain of the text.

settings JsonSerializerSettings

The settings of the deserializer. (default: Null)

Returns

T

Type Parameters

T

The type to convert.

ToObject<T>(string, string, JsonSerializerSettings?)

Converts a Json object to a typed object.

public static T? ToObject<T>(string text, string domain, JsonSerializerSettings? settings = null)

Parameters

text string

The text to deserialize

domain string

The domain of the text.

settings JsonSerializerSettings

The settings of the deserializer. (default: Null)

Returns

T

Type Parameters

T

The type to convert.

ToPrettyString<T>(T)

public static string ToPrettyString<T>(T obj)

Parameters

obj T

Returns

string

Type Parameters

T

ToString<T>(T)

public static string ToString<T>(T obj)

Parameters

obj T

Returns

string

Type Parameters

T

setupLoadSettings(bool)

public static void setupLoadSettings(bool ramOptimized)

Parameters

ramOptimized bool