Json Input TOP - getting list as array of strings

   2191   2   1
User Avatar
Member
387 posts
Joined: 11月 2008
Offline
Hi, is it possible to get a list (tuple, array) from JSON as a string array attribute without prior knowledge of how many items it contains?

Example JSON Input file retrieves e.g.: carparks/2/payment_methods as 3 entries:


But if I don't know how many entries it has, is it still possible to do the same thing with JSON Input TOP and get back string array attribute?

E.g: this does not work (error):


Error:
setStringAttrib(): incompatible function arguments. The following argument types are supported:
1. (self: _pdg.WorkItem, name: unicode, value: unicode, index: int=0L) -> None
2. (self: _pdg.WorkItem, arg0: unicode, arg1: UT_Array[unicode]) -> None

Invoked with: <GenericData name='jsoninput130_6', id=745 at 0x00000000b69b9e00>, u'payment_methods', [u'Bills', u'Coins', u'Charge (Visa / Mastercard / American Express Only)'], 0

Error running Python callback 'onGenerate':
Traceback (most recent call last):
File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.391/houdini/pdg/types\utils\jsondata.py", line 179, in onGenerate
processOpForFile(result.path, upstream_item, op)
File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.391/houdini/pdg/types\utils\jsondata.py", line 159, in processOpForFile
self.arrayRetrieve(item_holder, upstream_item, file_in)
File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.391/houdini/pdg/types\utils\jsondata.py", line 279, in arrayRetrieve
self._dive(item_holder, upstream_item, field, splitarray, query, json_data)
File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.391/houdini/pdg/types\utils\jsondata.py", line 373, in _dive
self._addAttrToItem(nitem, json_data, field, attr_index)
File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.391/houdini/pdg/types\utils\jsondata.py", line 392, in _addAttrToItem
nitem.setStringAttrib(attributename, obj[field], attr_index)
TypeError: setStringAttrib(): incompatible function arguments. The following argument types are supported:
1. (self: _pdg.WorkItem, name: unicode, value: unicode, index: int=0L) -> None
2. (self: _pdg.WorkItem, arg0: unicode, arg1: UT_Array[unicode]) -> None

Invoked with: <GenericData name='jsoninput130_6', id=745 at 0x00000000b69b9e00>, u'payment_methods', [u'Bills', u'Coins', u'Charge (Visa / Mastercard / American Express Only)'], 0

(My current workaround is Python Script TOP)
Edited by pezetko - 2020年4月3日 08:38:35

Attachments:
json_query_list.png (48.4 KB)
json_query_list_not_working.png (33.6 KB)

User Avatar
スタッフ
387 posts
Joined: 8月 2017
Offline
Hi there,

Both of your queries are technically correct, but this is not currently supported. There needs to be options for “String Array”, “Integer Array”, and “Float Array” added to the “PDG Attribte Type” parameter. I will add an RFE for this and update this thread once it has been added to the node.

Thank you!
User Avatar
スタッフ
387 posts
Joined: 8月 2017
Offline
Hi again,

Starting in tomorrow's build of Houdini 18.0, there will be now be “String Array”, “Integer Array”, and “Float Array” options in the “PDG Attribute Type” menu that allow you to retrieve arrays as an attribute automatically.
  • Quick Links