Skip to content

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

Signatures:

json create_json()

Usage:  {</>}


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_

Parameters:

NameTypeDescription
json_stringStringThe JSON formatted String to be converted to a Json object.

Return Type: Json

Signatures:

json create_json(string json_string)

Releases all of the Json objects which have been loaded.

Signatures:

void free_all_json()

Usage:  {</>}


Frees the SplashKit resources associated with the Json object.

Parameters:

NameTypeDescription
jJsonThe Json object whose resources should be released.

Signatures:

void free_json(json j)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object to count keys.

Return Type: Integer

Signatures:

int json_count_keys(json j)

Converts a Color to a Json object.

Parameters:

NameTypeDescription
clrColorThe Color to convert to Json.

Return Type: Json

Signatures:

json json_from_color(color clr)

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

Parameters:

NameTypeDescription
filenameStringThe filename of the file to be written to Resources/json/.

Return Type: Json

Signatures:

json json_from_file(const string &filename)

Usage:  {</>}


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

Parameters:

NameTypeDescription
j_stringStringA String in the JSON format.

Return Type: Json

Signatures:

json json_from_string(const string &j_string)

Usage:  {</>}


Checks if the Json object contains the given String key.

Parameters:

NameTypeDescription
jJsonThe Json object to check for the given key.
keyStringThe String key to be checked.

Return Type: Boolean

Signatures:

bool json_has_key(json j, string key)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.
out_resultVectorThe 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)

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

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.
out_resultVectorThe 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)

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

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.
out_resultVectorThe 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)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.
out_resultVectorThe 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)

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

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.

Return Type: Boolean

Signatures:

bool json_read_bool(json j, string key)

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

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.

Return Type: Float

Signatures:

float json_read_number(json j, string key)

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

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.

Return Type: Double

Signatures:

double json_read_number_as_double(json j, string key)

Reads a integer value from the Json object for the given String key.

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.

Return Type: Integer

Signatures:

int json_read_number_as_int(json j, string key)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.

Return Type: Json

Signatures:

json json_read_object(json j, string key)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object from which data will be returned for the given key.
keyStringThe String key used to find data in the Json object.

Return Type: String

Signatures:

string json_read_string(json j, string key)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
valueVectorThe value to be inserted into the Json object.

Signatures:

void json_set_array(json j, string key, vector<string> value)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
valueVectorThe value to be inserted into the Json object.

Signatures:

void json_set_array(json j, string key, vector<double> value)

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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
valueVectorThe value to be inserted into the Json object.

Signatures:

void json_set_array(json j, string key, vector<bool> value)

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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
valueVectorThe value to be inserted into the Json object.

Signatures:

void json_set_array(json j, string key, vector<json> value)

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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
valueBooleanThe value to be inserted into the Json object.

Signatures:

void json_set_bool(json j, string key, bool value)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
valueIntegerThe value to be inserted into the Json object.

Signatures:

void json_set_number(json j, string key, int value)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
valueDoubleThe value to be inserted into the Json object.

Signatures:

void json_set_number(json j, string key, double value)

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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
valueFloatThe value to be inserted into the Json object.

Signatures:

void json_set_number(json j, string key, float value)

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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
objJsonThe value to be inserted into the Json object.

Signatures:

void json_set_object(json j, string key, json obj)

Usage:  {</>}


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

Parameters:

NameTypeDescription
jJsonThe Json object where data will be inserted for the given key.
keyStringThe String key where data will be stored in the Json object.
valueStringThe value to be inserted into the Json object.

Signatures:

void json_set_string(json j, string key, string value)

Usage:  {</>}


Converts a Json object to a Color object.

Parameters:

NameTypeDescription
jJsonThe Json to convert to a Color.

Return Type: Color

Signatures:

color json_to_color(json j)

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

Parameters:

NameTypeDescription
jJsonThe Json object to be written to file.
filenameStringThe filename of the file to be stored in Resources/json/

Signatures:

void json_to_file(json j, const string &filename)

Usage:  {</>}


Converts and returns the Json object as a String.

Parameters:

NameTypeDescription
jJsonThe Json object to be converted to a String.

Return Type: String

Signatures:

string json_to_string(json j)

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) or free_all_json() (to release all loaded Json objects).