From NWN Lexicon
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Nwnee logo.jpg Note: This article documents Neverwinter Nights: Enhanced Edition new content or changes/updates/fixes to 1.69 functions. These are all listed under the category and patches pages.

The json data type is used to manipulate complicated data structures in NWN, both existing objects and new "Nuklear UI" or "NUI" which do new GUI elements. This is only available in NWN:EE.

You don't write the JSON directly as such (as a string for instance), but you can build it in NWN using the in built functions. You may also convert an object to JSON or import a JSON file built externally and added to a SQLite DB. You can also save and load the JSON from Sql using nwscript.

You can dump the JSON you create to the log if you want to get it out of the game using WriteTimestampedLogEntry(JsonDump(jValue)). Alternatives to this are dumping in into an sqlite DB and reading it from there and printing it using SpeakString for the smallest of dumps and typing it out again.

There are a number of JSON Functions that can help manipulate, test, and use json.

With SQLite the JSON library is built in.


// Retrieves the soundset.2da line used for oCreature, or -1 on error.
int GetCreatureSoundset(object oCreature)
    if(GetObjectType(oCreature) != OBJECT_TYPE_CREATURE) return -1;

    // Convert to JSON
    json jGet = ObjectToJson(oCreature);

    // Retrieve the key
    jGet = JsonObjectGet(jGet, "SoundSetFile");

    if(JsonGetType(jGet) == JSON_TYPE_NULL)
        SpeakString("JsonObjectGet error 1: " + JsonGetError(jGet));
        return -1;

    // Retrieve the value
    jGet = JsonObjectGet(jGet, "value");

    if(JsonGetType(jGet) != JSON_TYPE_INTEGER)
        SpeakString("JsonObjectGet error 2: " + JsonGetError(jGet));
        return -1;

    return JsonGetInt(jGet);

See Also


JSON Functions