I have JSON response from an API that looks a bit like this (tidied up for the purpose of showing here):
{
"member": [
{
"id": "OBF-123",
"fieldspec": [
{
"assetattrid": "FIELD01",
"assetattribute": [
{
"datatype": "NUMERIC",
"description": "Length"
}
],
"numvalue": 13.4
},
{
"assetattrid": "FIELD02",
"assetattribute": [
{
"datatype": "ALN",
"description": "Fruit type"
}
],
"alnvalue": "Banana"
},
{
"assetattrid": "FIELD03",
"assetattribute": [
{
"datatype": "ALN",
"description": "Class"
}
],
"alnvalue": "N"
}
]
},
{
"id": "OBF-124",
"fieldspec": [
{
"assetattrid": "FIELD02",
"assetattribute": [
{
"datatype": "ALN",
"description": "Fruit type"
}
],
"alnvalue": "Apple"
},
{
"assetattrid": "FIELD01",
"assetattribute": [
{
"datatype": "NUMERIC",
"description": "Length"
}
]
},
{
"assetattrid": "FIELD03",
"assetattribute": [
{
"datatype": "ALN",
"description": "Class"
}
],
"alnvalue": "K"
}
]
}
]
}This defines the attributes for two objects returned from an API request, containing the field name (assetattrid) and alias (description), the field type (datatype) and finally the actual attribute value (numvalue/alnvalue). What I would like is to get properly named attributes like this:
| id | Length | Fruit type | Class |
|---|---|---|---|
| OBF-123 | 13.4 | Banana | N |
| OBF-124 | Apple | K |
A few complicating factors (and why I’d like to find a dynamic solution):
- The attributes (names, types and amounts) may be different depending on the data queried (different object types, query parameters etc)
- Some fields might be empty, like the missing numvalue for object 2 above, but the field definition seems to always be there
- The field order appears to be random



