Skip to content

Commit 6d59dd0

Browse files
committed
feat: alias 'undefined' as 'missing'
1 parent 4073a58 commit 6d59dd0

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- `JSONPathIndexError` now requires a `token` parameter. It used to be optional.
88

9+
**Features**
10+
11+
- `missing` is now an allowed alias of `undefined` when using the `isinstance()` filter function.
12+
913
## Version 0.6.0
1014

1115
**Breaking changes**

‎docs/functions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Return `True` if the type of _obj_ matches _t_. This function allows _t_ to be o
2626

2727
| type | aliases |
2828
| --------------------- | ------------------------------------ |
29-
| UNDEFINED | "undefined" |
29+
| UNDEFINED | "undefined", "missing" |
3030
| None | "null", "nil", "None", "none" |
3131
| str | "str", "string" |
3232
| Sequence (array-like) | "array", "list", "sequence", "tuple" |

‎jsonpath/function_extensions/is_instance.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __call__(self, obj: object, t: str) -> bool: # noqa: PLR0911
1717
Python "type". Some of these aliases follow JavaScript/JSON semantics.
1818
"""
1919
if obj is UNDEFINED or obj is UNDEFINED_LITERAL:
20-
return t == "undefined"
20+
return t in ("undefined", "missing")
2121
if obj is None:
2222
return t in ("null", "nil", "None", "none")
2323
if isinstance(obj, str):

‎tests/test_isinstance_function.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class Case:
4141
data={"some": [{"thing": "foo"}]},
4242
want=[{"thing": "foo"}],
4343
),
44+
Case(
45+
description="'missing' is an alias for 'undefined'",
46+
path="$.some[?is(@.other, 'missing')]", # things without `other`
47+
data={"some": [{"thing": "foo"}]},
48+
want=[{"thing": "foo"}],
49+
),
4450
Case(
4551
description="type of None",
4652
path="$.some[?is(@.thing, 'null')]",

0 commit comments

Comments
 (0)