If I want to extract specific properties from a JSON array using SQL, for example, if the requestparameters structure is as follows:
{
'gree': [
{
'Grantee': {
'xsi:type': 'CanonicalUser',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'ID': 'xx'
},
'Permission': 'READ'
},
{
'Grantee': {
'xsi:type': 'CanonicalUser',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'ID': 'xx'
},
'Permission': 'WRITE'
},
{
'Grantee': {
'xsi:type': 'CanonicalUser',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'ID': 'xx'
},
'Permission': 'WRITE_ACP'
}
]
}
If i were using MySQL, you could use the following syntax to extract all the ID properties and Permission properties:
SELECT
json_extract(requestparameters, '$.gree[*].Grantee.ID') as ID,
json_extract(requestparameters, '$.gree[*].Permission') as Permission
FROM table;
However, using [ * ] in this way is not valid syntax for Athena and would result in an error like 'INVALID_FUNCTION_ARGUMENT: Invalid JSON path: '$.AccessControlPolicy.AccessControlList.Grant[ * ].Permission''. If you replace [ * ] with [0], you can extract information from the first element. The question is, how can you extract properties from all elements?"