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.
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.