Whole file

sean2077/jsonpath-python

The author described this change as fix: resolve issue #16 support quoted keys in filters and paths. It counts as a record because the check below fails on the code as it stood at 47bba2512 and passes on 6caa9d4e0, with nothing else changed between the two runs.

Fix saved2025-11-23
Sharing licenceMIT · LICENSE
Change size+13 6

What the code was meant to do, written into the code itself as a save note

fix: resolve issue #16 support quoted keys in filters and paths

The change

118118 return f"#Q{n}"
119119
120120 def _put_quote(self, m):
121- return self.subx["#Q"][int(m.group(1))]
121+ return f"'{self.subx['#Q'][int(m.group(1))]}'"
122122
123123 def _get_backquote(self, m):
124124 n = len(self.subx["#BQ"])
146146
147147 @staticmethod
148148 def _gen_obj(m):
149+ content = m.group(1) or m.group(2) # group 2 is for len()
149150 ret = "__obj"
150- for e in m.group(1).split("."):
151+ for e in content.split("."):
152+ if len(e) >= 2 and ((e[0] == "'" and e[-1] == "'") or (e[0] == '"' and e[-1] == '"')):
153+ e = e[1:-1]
151154 ret += f'["{e}"]'
152155 return ret
153156
239242 return
240243
241244 # get value from dict
242- if isinstance(obj, dict) and step in obj:
243- if re.match(r"^\w+$", step):
244- self._trace(obj[step], i + 1, f"{path}.{step}")
245+ step_key = step
246+ if len(step) >= 2 and step[0] == "'" and step[-1] == "'":
247+ step_key = step[1:-1]
248+
249+ if isinstance(obj, dict) and step_key in obj:
250+ if re.match(r"^\w+$", step_key):
251+ self._trace(obj[step_key], i + 1, f"{path}.{step_key}")
245252 else:
246- self._trace(obj[step], i + 1, f"{path}['{step}']")
253+ self._trace(obj[step_key], i + 1, f"{path}['{step_key}']")
247254 return
248255
249256 # slice

The check that tells the two apart

failpass·tests/test_issues.py::test_issue_16_quoted_keys

Check file tests/test_issues.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it47bba251233b8f96963dc22e2e83238b417e332a
Broken version dated2025-11-23
Modulejsonpath.jsonpath
Units changedJSONPath
Fingerprint5ad8c686f74de7f6
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in sean2077/jsonpath-python