Hackers,
The jsonpath doc[1] has an excellent description of the format of strings, but
for unquoted path keys, it simply says:
> Member accessor that returns an object member with the specified key. If the
> key name matches some named variable starting with $ or does not meet the
> JavaScript rules for an identifier, it must be enclosed in double quotes to
> make it a string literal.
I went looking for the JavaScript rules for an identifier and found this in the
MDN docs[2]:
> In JavaScript, identifiers can contain Unicode letters, $, _, and digits
> (0-9), but may not start with a digit. An identifier differs from a string in
> that a string is data, while an identifier is part of the code. In
> JavaScript, there is no way to convert identifiers to strings, but sometimes
> it is possible to parse strings into identifiers.
However, the Postgres parsing of jsonpath keys appears to follow the same rules
as strings, allowing backslash escapes:
david=# select '$.fo\u00f8 == $x'::jsonpath;
jsonpath -------------------
($."foø" == $"x")
This would seem to contradict the documentation. Is this behavior required by
the SQL standard? Do the docs need updating? Or should the code actually follow
the JSON identifier behavior?
Thanks,
David
PS: Those excellent docs on strings mentions support for \v, but the grammar in
the right nav of https://www.json.org/json-en.html does not. Another bonus
feature?
[1]: https://www.postgresql.org/docs/16/datatype-json.html#DATATYPE-JSONPATH
[2]: https://developer.mozilla.org/en-US/docs/Glossary/Identifier