JsonToObject(json, location, object, int)

From NWN Lexicon
Jump to navigationJump to search
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.

Deserializes the game object described in jObject.

object JsonToObject(
    json jObject,
    location locLocation,
    object oOwner = OBJECT_INVALID,
    int bLoadObjectState = FALSE


object to deserialize from json.
specifies the location where the object is created.
object owner. If valid, for valid use cases, the object is placed in owner's inventory and locLocation is ignored.
specifies whether to include more detailed info in some cases; see below.


Deserializes the game object described in jObject.

Returns OBJECT_INVALID on errors.

Supported object types: creature, item, trigger, placeable, door, waypoint, encounter, store, area (combined format). For areas, locLocation is ignored.

If bLoadObjectState is TRUE, local vars, effects, action queue, and transition info (triggers, doors) are read in.


Use TemplateToJson to easily initially generate the JSON needed, else you'll be rolling your own by hand - there is no loadable JSON datatype at the moment.

Once generated make tweaks and changes then use this function to spawn it into the world.


This function was added in 1.85.8193.31 of NWN:EE.


Example will take a placeable of resref "plc_resref" (invalid - replace with your own) and alter the appearance to line ID 33, a Ballista, then spawn it.

#include "nw_inc_gff"
void main()
    // Generate JSON from resref template
    json jPlaceable = TemplateToJson("plc_resref", RESTYPE_UTP);
    // Change to appearance 390
    jPlaceable = GffReplaceDword(jPlaceable, "Appearance", 33);
    // Spawn
    JsonToObject(jPlaceable, GetLocation(OBJECT_SELF));

See Also


JSON Functions GFF Functions GffReplaceDword ObjectToJson TemplateToJson