JSON

SplashKit Json allows you to create and read JSON objects.

Splashkit's JSON library allows you to easily create or read JSON objects and manipulate them to/from a JSON string or from a file containing a JSON string. Create a new JSON object with a call to Create JSON() and read or write data to it by calling methods like JSON Add String(json J, String Key, String Value) and JSON Read String(json J, String Key).

JSON Guides

Using JSON

Functions

Create JSON

This function is overloaded. The following versions exist.

Create JSON

The empty JSON object returned can be filled with data and read by the functions and procedures prefixed with JSON Add and JSON Read

Return Type

JSON

Returns an empty JSON object.

Signatures
json create_json()
public static Json SplashKit.CreateJson();
public Json();
function CreateJson(): Json
def create_json():
Guides
Using JSON

Create JSON

String JSON String must be valid JSON. The JSON object returned can be filled with data and read by the functions and procedures prefixed with JSON Add and JSON Read

Return Type

JSON

Returns a JSON object filled with data from the parameter String.

Parameters
Name Type Description
JSON String

String

The JSON formatted String to be converted to a JSON object.

Signatures
json create_json(string json_string)
public static Json SplashKit.CreateJson(string jsonString);
public Json(string jsonString);
function CreateJson(jsonString: String): Json
def create_json_from_string(json_string):
Guides
Using JSON

Free All JSON

Releases all of the JSON objects which have been loaded.

Signatures
void free_all_json()
public static void Json.FreeAllJson();
public static void SplashKit.FreeAllJson();
procedure FreeAllJson()
def free_all_json():

Free JSON

Frees the SplashKit resources associated with the JSON object.

Parameters
Name Type Description
J

JSON

The JSON object whose resources should be released.

Signatures
void free_json(json j)
public void Json.FreeJson();
public static void SplashKit.FreeJson(Json j);
procedure FreeJson(j: Json)
def free_json(j):
Guides
Using JSON

JSON Count Keys

Returns the count of keys in the top-level JSON object.

Return Type

Integer

The count of keys in the top-level JSON object.

Parameters
Name Type Description
J

JSON

The JSON object to count keys.

Signatures
int json_count_keys(json j)
public int Json.JsonCountKeys();
public static int SplashKit.JsonCountKeys(Json j);
function JsonCountKeys(j: Json): Integer
def json_count_keys(j):

JSON From Color

Converts a Color to a JSON object.

Return Type

JSON

The Color serialized into a JSON object.

Parameters
Name Type Description
Clr

Color

The Color to convert to JSON.

Signatures
json json_from_color(color clr)
public static Json Json.JsonFromColor(Color clr);
public static Json SplashKit.JsonFromColor(Color clr);
function JsonFromColor(clr: Color): Json
def json_from_color(clr):

JSON From File

Reads a JSON object from a JSON string stored in Resources/json/filename and loads the data into the returned JSON object.

Return Type

JSON

Returns the JSON object loaded from the JSON file in Filename.

Parameters
Name Type Description
Filename

String

The filename of the file to be written to Resources/json/.

Signatures
json json_from_file(const string &filename)
public static Json Json.JsonFromFile(string filename);
public static Json SplashKit.JsonFromFile(string filename);
function JsonFromFile(const filename: String): Json
def json_from_file(filename):

JSON From String

Reads a JSON object from a String in the JSON format.

Return Type

JSON

Returns a JSON object loaded with data from String J String.

Parameters
Name Type Description
J String

String

A String in the JSON format.

Signatures
json json_from_string(const string &j_string)
public static Json Json.JsonFromString(string jString);
public static Json SplashKit.JsonFromString(string jString);
function JsonFromString(const jString: String): Json
def json_from_string(j_string):

JSON Has Key

Checks if the JSON object contains the given String key.

Return Type

Boolean

Returns True if the JSON J object contains a key for String key.

Parameters
Name Type Description
J

JSON

The JSON object to check for the given key.

Key

String

The String key to be checked.

Signatures
bool json_has_key(json j, string key)
public bool Json.JsonHasKey(string key);
public static bool SplashKit.JsonHasKey(Json j, string key);
function JsonHasKey(j: Json; key: String): Boolean
def json_has_key(j, key):

JSON Read Array

JSON Read Array

Reads an array of Double values from the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Out Result

Dynamic Array

The array which will be filled with the data stored for String key.

Signatures
void json_read_array(json j, string key, vector<double> &out_result)
public void Json.JsonReadArray(string key, ref List<double> outResult);
public static void SplashKit.JsonReadArray(Json j, string key, ref List<double> outResult);
procedure JsonReadArray(j: Json; key: String; var outResult: ArrayOfDouble)
def json_read_array_of_double(j, key, out_result):

JSON Read Array

Reads an array of JSON object values from the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Out Result

Dynamic Array

The array which will be filled with the data stored for String key.

Signatures
void json_read_array(json j, string key, vector<json> &out_result)
public void Json.JsonReadArray(string key, ref List<Json> outResult);
public static void SplashKit.JsonReadArray(Json j, string key, ref List<Json> outResult);
procedure JsonReadArray(j: Json; key: String; var outResult: ArrayOfJson)
def json_read_array_of_json(j, key, out_result):

JSON Read Array

Reads an array of String values from the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Out Result

Dynamic Array

The array which will be filled with the data stored for String key.

Signatures
void json_read_array(json j, string key, vector<string> &out_result)
public void Json.JsonReadArray(string key, ref List<string> outResult);
public static void SplashKit.JsonReadArray(Json j, string key, ref List<string> outResult);
procedure JsonReadArray(j: Json; key: String; var outResult: ArrayOfString)
def json_read_array_of_string(j, key, out_result):

JSON Read Array

Reads an array of Boolean values from the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Out Result

Dynamic Array

The array which will be filled with the data stored for String key.

Signatures
void json_read_array(json j, string key, vector<bool> &out_result)
public void Json.JsonReadArray(string key, ref List<bool> outResult);
public static void SplashKit.JsonReadArray(Json j, string key, ref List<bool> outResult);
procedure JsonReadArray(j: Json; key: String; var outResult: ArrayOfBoolean)
def json_read_array_of_bool(j, key, out_result):

JSON Read Boolean

Reads a Boolean value from the JSON object for the given String key.

Return Type

Boolean

Returns the Boolean value stored at the String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Signatures
bool json_read_bool(json j, string key)
public bool Json.JsonReadBool(string key);
public static bool SplashKit.JsonReadBool(Json j, string key);
function JsonReadBool(j: Json; key: String): Boolean
def json_read_bool(j, key):

JSON Read Number

Reads a Float value from the JSON object for the given String key.

Return Type

Float

Returns the Float value stored at the String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Signatures
float json_read_number(json j, string key)
public float Json.JsonReadNumber(string key);
public static float SplashKit.JsonReadNumber(Json j, string key);
function JsonReadNumber(j: Json; key: String): Single
def json_read_number(j, key):

JSON Read Number As Double

Reads a Double value from the JSON object for the given String key.

Return Type

Double

Returns the Double value stored at the String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Signatures
double json_read_number_as_double(json j, string key)
public double Json.JsonReadNumberAsDouble(string key);
public static double SplashKit.JsonReadNumberAsDouble(Json j, string key);
function JsonReadNumberAsDouble(j: Json; key: String): Double
def json_read_number_as_double(j, key):

JSON Read Number As Integer

Reads a Integer value from the JSON object for the given String key.

Return Type

Integer

Returns the Integer value stored at the String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Signatures
int json_read_number_as_int(json j, string key)
public int Json.JsonReadNumberAsInt(string key);
public static int SplashKit.JsonReadNumberAsInt(Json j, string key);
function JsonReadNumberAsInt(j: Json; key: String): Integer
def json_read_number_as_int(j, key):

JSON Read Object

Reads a JSON object value from the JSON object for the given String key.

Return Type

JSON

Returns the JSON object value stored at the String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Signatures
json json_read_object(json j, string key)
public Json Json.JsonReadObject(string key);
public static Json SplashKit.JsonReadObject(Json j, string key);
function JsonReadObject(j: Json; key: String): Json
def json_read_object(j, key):

JSON Read String

Reads a String value from the JSON object for the given String key.

Return Type

String

Returns the String value stored at the String key.

Parameters
Name Type Description
J

JSON

The JSON object from which data will be returned for the given key.

Key

String

The String key used to find data in the JSON object.

Signatures
string json_read_string(json j, string key)
public string Json.JsonReadString(string key);
public static string SplashKit.JsonReadString(Json j, string key);
function JsonReadString(j: Json; key: String): String
def json_read_string(j, key):

JSON Set Array

JSON Set Array

Adds an array of String values to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Value

Dynamic Array

The value to be inserted into the JSON object.

Signatures
void json_set_array(json j, string key, vector<string> value)
public void Json.JsonSetArray(string key, List<string> value);
public static void SplashKit.JsonSetArray(Json j, string key, List<string> value);
procedure JsonSetArray(j: Json; key: String; value: ArrayOfString)
def json_set_array_of_string(j, key, value):

JSON Set Array

Adds an array of Double values to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Value

Dynamic Array

The value to be inserted into the JSON object.

Signatures
void json_set_array(json j, string key, vector<double> value)
public void Json.JsonSetArray(string key, List<double> value);
public static void SplashKit.JsonSetArray(Json j, string key, List<double> value);
procedure JsonSetArray(j: Json; key: String; value: ArrayOfDouble)
def json_set_array_of_double(j, key, value):

JSON Set Array

Adds an array of Boolean values to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Value

Dynamic Array

The value to be inserted into the JSON object.

Signatures
void json_set_array(json j, string key, vector<bool> value)
public void Json.JsonSetArray(string key, List<bool> value);
public static void SplashKit.JsonSetArray(Json j, string key, List<bool> value);
procedure JsonSetArray(j: Json; key: String; value: ArrayOfBoolean)
def json_set_array_of_bool(j, key, value):

JSON Set Array

Adds an array of JSON object values to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Value

Dynamic Array

The value to be inserted into the JSON object.

Signatures
void json_set_array(json j, string key, vector<json> value)
public void Json.JsonSetArray(string key, List<Json> value);
public static void SplashKit.JsonSetArray(Json j, string key, List<Json> value);
procedure JsonSetArray(j: Json; key: String; value: ArrayOfJson)
def json_set_array_of_json(j, key, value):

JSON Set Boolean

Adds a Boolean value to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Value

Boolean

The value to be inserted into the JSON object.

Signatures
void json_set_bool(json j, string key, bool value)
public void Json.JsonSetBool(string key, bool value);
public static void SplashKit.JsonSetBool(Json j, string key, bool value);
procedure JsonSetBool(j: Json; key: String; value: Boolean)
def json_set_bool(j, key, value):

JSON Set Number

JSON Set Number

Adds an Integer value to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Value

Integer

The value to be inserted into the JSON object.

Signatures
void json_set_number(json j, string key, int value)
public void Json.JsonSetNumber(string key, int value);
public static void SplashKit.JsonSetNumber(Json j, string key, int value);
procedure JsonSetNumber(j: Json; key: String; value: Integer)
def json_set_number_integer(j, key, value):
Guides
Using JSON

JSON Set Number

Adds a Double value to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Value

Double

The value to be inserted into the JSON object.

Signatures
void json_set_number(json j, string key, double value)
public void Json.JsonSetNumber(string key, double value);
public static void SplashKit.JsonSetNumber(Json j, string key, double value);
procedure JsonSetNumber(j: Json; key: String; value: Double)
def json_set_number_double(j, key, value):
Guides
Using JSON

JSON Set Number

Adds a Float value to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Value

Float

The value to be inserted into the JSON object.

Signatures
void json_set_number(json j, string key, float value)
public void Json.JsonSetNumber(string key, float value);
public static void SplashKit.JsonSetNumber(Json j, string key, float value);
procedure JsonSetNumber(j: Json; key: String; value: Single)
def json_set_number_float(j, key, value):
Guides
Using JSON

JSON Set Object

Adds a JSON object to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Obj

JSON

The value to be inserted into the JSON object.

Signatures
void json_set_object(json j, string key, json obj)
public void Json.JsonSetObject(string key, Json obj);
public static void SplashKit.JsonSetObject(Json j, string key, Json obj);
procedure JsonSetObject(j: Json; key: String; obj: Json)
def json_set_object(j, key, obj):

JSON Set String

Adds a String value to the JSON object for the given String key.

Parameters
Name Type Description
J

JSON

The JSON object where data will be inserted for the given key.

Key

String

The String key where data will be stored in the JSON object.

Value

String

The value to be inserted into the JSON object.

Signatures
void json_set_string(json j, string key, string value)
public void Json.JsonSetString(string key, string value);
public static void SplashKit.JsonSetString(Json j, string key, string value);
procedure JsonSetString(j: Json; key: String; value: String)
def json_set_string(j, key, value):
Guides
Using JSON

JSON To Color

Converts a JSON object to a Color object.

Return Type

Color

The Color deserialized from the JSON object.

Parameters
Name Type Description
J

JSON

The JSON to convert to a Color.

Signatures
color json_to_color(json j)
public static Color Json.JsonToColor(Json j);
public static Color SplashKit.JsonToColor(Json j);
function JsonToColor(j: Json): Color
def json_to_color(j):

JSON To File

Writes the JSON object to a JSON string stored in Resources/json/filename.

Parameters
Name Type Description
J

JSON

The JSON object to be written to file.

Filename

String

The filename of the file to be stored in Resources/json/

Signatures
void json_to_file(json j, const string &filename)
public static void Json.JsonToFile(Json j, string filename);
public static void SplashKit.JsonToFile(Json j, string filename);
procedure JsonToFile(j: Json; const filename: String)
def json_to_file(j, filename):

JSON To String

Converts and returns the JSON object as a String.

Return Type

String

Returns the JSON object as a String.

Parameters
Name Type Description
J

JSON

The JSON object to be converted to a String.

Signatures
string json_to_string(json j)
public static string Json.JsonToString(Json j);
public static string SplashKit.JsonToString(Json j);
function JsonToString(j: Json): String
def json_to_string(j):

Types

JSON

The JSON type is used to refer to objects in the JSON format that can be manipulated by the SplashKit JSON functions and procedures.

All JSON objects are:

  • created with Create JSON() or Create JSON(string S) or JSON From String(string S) or JSON From File(json J)

  • and must be released using Free JSON() (to release a specific json object) orFree All JSON()(to release all loadedjson objects).