-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjson_path_probe.py
More file actions
35 lines (33 loc) · 1.07 KB
/
Copy pathjson_path_probe.py
File metadata and controls
35 lines (33 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sqlite3
conn = sqlite3.connect(":memory:")
cases = [
(
"attr_dollar_quoted",
"select json_extract('{\"gen_ai.system\":\"anthropic\"}', '$.\"gen_ai.system\"')",
),
(
"attr_bracket_quoted",
"select json_extract('{\"gen_ai.system\":\"anthropic\"}', '$[\"gen_ai.system\"]')",
),
(
"attr_single_quoted",
"select json_extract('{\"gen_ai.system\":\"anthropic\"}', '$[''gen_ai.system'']')",
),
(
"res_dollar_quoted",
"select json_extract('{\"attributes\":{\"service.name\":\"gateway\"}}', '$.attributes.\"service.name\"')",
),
(
"res_bracket_quoted",
"select json_extract('{\"attributes\":{\"service.name\":\"gateway\"}}', '$.attributes[\"service.name\"]')",
),
(
"res_single_quoted",
"select json_extract('{\"attributes\":{\"service.name\":\"gateway\"}}', '$.attributes[''service.name'']')",
),
]
for name, sql in cases:
try:
print(name, conn.execute(sql).fetchone()[0])
except Exception as exc:
print(name, "ERROR", exc)