JSON path syntax for arrays within a GFF
Proleric
Member Posts: 1,316
I've successfully loaded a UTC into a JSON and can edit top-level fields.
Does anyone know the syntax for a path into an array within the GFF structure?
The comments in nw_inc_gff led me to try the third line below:
However, that line fails:
[Fri Oct 8 15:53:14] [json.exception.other_error.501] unsuccessful: {"op":"test","path":"/Equip_ItemList/0/EquippedRes/type","value":"resref"}
Error while deserializing object: [json.exception.type_error.305] cannot use operator[] with a string argument with null
Does anyone know the syntax for a path into an array within the GFF structure?
The comments in nw_inc_gff led me to try the third line below:
json jTemplate = TemplateToJson(sTemplate, RESTYPE_UTC);
jTemplate = GffReplaceByte (jTemplate, "Gender", nGender);
jTemplate = GffReplaceResRef(jTemplate, "Equip_ItemList/0/EquippedRes", sDress);
However, that line fails:
[Fri Oct 8 15:53:14] [json.exception.other_error.501] unsuccessful: {"op":"test","path":"/Equip_ItemList/0/EquippedRes/type","value":"resref"}
Error while deserializing object: [json.exception.type_error.305] cannot use operator[] with a string argument with null
0
Comments
I'm pretty sure what's wrong is the path syntax - the documentation says the leading / should be omitted but doesn't give an explicit example of an array. [0] doesn't work, either.
Maybe you cannot do it in one line. Something like: Sorry that code probably doesn't work, but is going the tedious direction I would try.
I also tried 1 instead of 0, same error.
"Equip_ItemList": { "type": "list", "value": [ { "EquippedRes": { "type": "resref", "value": "nw_wblml001" }, "__struct_id": 16 }, { "EquippedRes": { "type": "resref", "value": "nw_it_creitem055" }, "__struct_id": 131072 } ] },So in order to replace the resref of the first item you need to do something like this:
That works! Thanks!
Counter-intuitive, though. The quickest and most obvious way to discover the key names is to use a GFF editor. However, the keyword "value" isn't in the GFF itself, being inserted by TemplateToJson() to comply with the Json standard.
Hopefully, there is a general rule that every array in a GFF requires a path element value/# to access element number # in the Json?
Here's an example, examining the item properties of a UTI.
Not sure that it's much clearer - notice that the keyword "value" still has to be inserted - taking your point that there's no direct helper function.
// Determine whether clothing is rich, poor or neutal int zDressStatus(string sDress) { int CLOTHING_NEUTRAL = 0; int nProperty; json jItem = TemplateToJson(sDress, RESTYPE_UTI); json jProperties = GffGetList(jItem, "PropertiesList"); int n = -1; json jProperty = JsonArrayGet(jProperties, ++n); while (JsonGetType(jProperty) != JSON_TYPE_NULL) { nProperty = JsonGetInt(JsonObjectGet(JsonObjectGet(jProperty, "PropertyName"), "value")); if ((nProperty == ITEM_PROPERTY_CLOTHING_POOR) || (nProperty == ITEM_PROPERTY_CLOTHING_RICH)) return nProperty; jProperty = JsonArrayGet(jProperties, ++n); } return CLOTHING_NEUTRAL; }