JsonGetType(json)
From NWN Lexicon
Jump to navigationJump to search
Describes the type of the given json value.
int JsonGetType(
json jValue
);
Parameters
- jValue
- The json to analyze.
Description
Returns a JSON_TYPE_* constant.
Remarks
Returns JSON_TYPE_NULL if the value is empty. Testing JSON_TYPE_NULL is a good standard for testing Json validity (compared to testing return values being blank).
Depending on data type and your use case, after checking for JSON_TYPE_NULL you may wish to test that it has data with JsonGetLength (that is, it could be non-null, but zero size).
For example:
json jsonData = JsonArray();
This will be NON-null, but won't have data (size 0).
Version
This function was added in 1.85.8193.31 of NWN:EE.
Example
// Try to get some saved json.
json jsonData = GetLocalJson(GetModule(), "MYJSON");
if (JsonGetType(jsonData) != JSON_TYPE_NULL)
{
// data is NOT null, so can process it here.
}
else
{
// data IS null, so log it if unexpected.
SendMessageToAllDMs("JsonData for MYJSON is null!");
}
See Also
| functions: |