This appears to be the result of a recent change to the json_extract_path_text function, where it fails on arrays.
As Craig points out, technically the error is correct as this is an array and not a json object.
You might be tempted to use json_extract_array_element_text('json string', pos) as in:
json_extract_path_text(json_extract_array_element_text(my_field, 0), 'some_key')
But if your data is a mix of objects and arrays, this will also fail with the equally-technically-correct-yet-really-just-annoying error of
"context: invalid json array object {"somekey":"somevalue"}"
Of course, the beauty of these fails is that a single wonk out will also kill your entire query. One workaround might be a UDF, such as the following:
create or replace function f_extract_if_list (j varchar(max))
returns varchar(max)
stable
as $$
import json
if not j:
return None
try:
parsed_j = json.loads(j)
except ValueError:
return ''
if isinstance(parsed_j, dict):
return j
if isinstance(parsed_j, list) and len(parsed_j) >= 1:
return json.dumps(parsed_j[0])
return ''
$$ language plpythonu;
Which checks to see if the item is an array or not and if so, returns the first element of that array. It might need some tweaking depending on your specific use case.
More info on UDFs can be found here: http://docs.aws.amazon.com/redshift/latest/dg/user-defined-functions.html
Either way, I've posted something about this in the AWS forums too:
https://forums.aws.amazon.com/thread.jspa?messageID=728647&
Hope that helps!
[], i.e. the json is a single empty array? Because if so, an array isn't a json object, empty or otherwise, it's an array. You can't get a field of an array.[]is a valid json document but it's not a json object. You can't look up a key in an array, they only have indexes. That said, PostgreSQL (9.5, at least) allows this. So I'm guessing it's a redshift problem.