Skip to content

Json

Functions

Create Json

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

Usage:

Signatures:

json create_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_

Parameters:

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

Return Type: Json

Signatures:

json create_json(string json_string)

Free All Json

Releases all of the Json objects which have been loaded.

Usage:

Signatures:

void free_all_json()

Free Json

Frees the SplashKit resources associated with the Json object.

Parameters:

NameTypeDescription
jJsonThe Json object whose resources should be released.

Usage:

Signatures:

void free_json(json j)

Json Count Keys

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)

Json From Color

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)

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.

Parameters:

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

Return Type: Json

Usage:

Signatures:

json json_from_file(const string &filename)

Json From String

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

Parameters:

NameTypeDescription
j_stringStringA String in the JSON format.

Return Type: Json

Usage:

Signatures:

json json_from_string(const string &j_string)

Json Has Key

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

Usage:

Signatures:

bool json_has_key(json j, string key)

Json Read Array

Json Read Array

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)

Json Read Array

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)

Json Read Array

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.

Usage:

Signatures:

void json_read_array(json j, string key, vector<string> &out_result)

Json Read Array

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)

Json Read Bool

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)

Json Read Number

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)

Json Read Number As Double

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)

Json Read Number As Int

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

Usage:

Signatures:

int json_read_number_as_int(json j, string key)

Json Read Object

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

Usage:

Signatures:

json json_read_object(json j, string key)

Json Read String

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

Usage:

Signatures:

string json_read_string(json j, string key)

Json Set Array

Json Set Array

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.

Usage:

Signatures:

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

Json Set Array

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)

Json Set Array

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)

Json Set Array

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)

Json Set Bool

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.

Usage:

Signatures:

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

Json Set Number

Json Set Number

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.

Usage:

Signatures:

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

Json Set Number

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)

Json Set Number

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)

Json Set Object

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.

Usage:

Signatures:

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

Json Set String

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.

Usage:

Signatures:

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

Json To Color

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)

Json To File

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/

Usage:

Signatures:

void json_to_file(json j, const string &filename)

Json To String

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)

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