I have a "~" in my json fields, such as "~id". Using Presto 0.75, I am unable to access such fields. Following is what I have tried so far without success:
SELECT json_extract_scalar('{"id":"1","table":"test"}', '$.table'); // This works
SELECT json_extract_scalar('{"id":"1","~table":"test"}', '$.[\"~table\"]'); // Doesn't work
SELECT json_extract_scalar('{"id":"1","~table":"test"}', '$.[\~table]'); // Doesn't work
Error given is "Invalid JSON path:"
The correct form for that JSON path is:
'$["~table"]'
:Here are some facts to help you understand why the alternatives you tried don't work:
'don''t'
is the SQL string literal fordon't
. Double quotes within a SQL string literal do not need to be escaped.'$["foo"]'
or'$.foo'
. The field access syntax only works for names that are valid identifiers (alphanumeric and underscores).