JsonaValue - Paranoid-AF/Jsona GitHub Wiki

The JsonaValue class is how values in JSON will be stored. Every single value created by Jsona is actually stored in JsonaValue, even arrays and objects in JSON are converted to arrays and dictionaries of JsonaValue.

Syntax

There are currently 7 ways of instantiation, depending on which type this object will store.

Value() - Initialize with null.

Value(bool value) - Initialize with a boolean value.

Value(string value) - Initialize with a string value.

Value(int value) - Initialize with a integer value.

Value(double value) - Initialize with a real number value.

Value(array<Value@> value) - Initialize with an array.

Value(dictionary value) - Initialize with a dictionary.

Enum

Constants refer to a specific type of value.

enum ValueType{
  OBJECT_VALUE = 1,
  ARRAY_VALUE = 2,
  BOOLEAN_VALUE = 4,
  STRING_VALUE = 8,
  INT_VALUE = 16,
  REAL_VALUE = 32,
  NULL_VALUE = 64
}

Methods

set

Changes the stored value to another value.

void set() - Set to null.

void set(bool value) - Set to a boolean value.

void set(string value) - Set to a string value.

void set(int value) - Set to a integer value.

void set(double value) - Set to a real number value.

void set(array<Value@> value) - Set to an array.

void set(dictionary value) - Set to a dictionary.

type

Gets which type the store value is. ValueType type() - Gets which type the store value is. See more about ValueType here.

get

Gets the stored value. However, you should always get the value type to use the correct method before getting the value, unless you're confident about that.

To get the value inside JsonaValue, you just need to convert it into its designated type.

bool(JsonaValue@) - Get a boolean value.

string(JsonaValue@) - Get a string value.

int(JsonaValue@) - Get a integer value.

double(JsonaValue@) - Get a real number value.

array<Value@>(JsonaValue@) - Get an array.

dictionary(JsonaValue@) - Get a dictionary.

(There's no method for null type, as...null is null, null never changes.)

NOTE: It's recommended to use handles to array / dictionary, so when you modify the values within the array / dictionary, that array / dictionary in Value will also be modified. In this case, you won't need to use set methods every time you modify a value in the array / dictionary. This is bidirectional data flow, and it also saves memory.

Example: dictionary@ dic = dictionary(val); dic["node"] = JsonaValue("paranoid_af");

The key is that @.

stringify

To stringify current JsonaValue, just use stringify() method. It returns a string, which...is stringified JSON value. It's that simple.

Operator Overloads

For ease of access, JsonaValue overloads index operators, as you might want your code stylised like this:

variable[0]["key"][0]["key1"] // Not working though.

In this case, JsonaValue accesses the value inside the array / dictionary for you. So you will always get the result as a JsonaValue. Get and set are both supported.

However, due to limitation of AngelScript, you have to access an array value with a numeric string.

variable["0"]["key"]["0"]["key1"] // This works.
⚠️ **GitHub.com Fallback** ⚠️